How to use existing Java API tests inside Jmeter - java

We have existing Java tests that singularly tests our back end. These tests are pretty elaborate, and also run as a single users. I would like to know if I can simply take these existing tests/classes/libraries/jars etc and just wrap JMeter around them to execute them as JMeter tests from the command line (i.e. Maven).
Maybe add in some listeners and other JMeter components, but the tests are perfect the way they are except that they are not multi-threaded and do not have the reporting functions that JMeter has.
Can this be done using JSR233?
What if my libraries are located elsewhere? How can I use them in the JMeter project?

You have at least 3 options:
Implement JavaSamplerClient by extending AbstractJavaSamplerClient, this class will call your class. Create a Jar from this and put it in jmeter/lib/ext + add dependencies to jmeter/lib folder and you can then use Java Request and select your class.
Use JSR223 Sampler + Groovy wrapper for your class
Use JUnit Sampler if you have some JUnit classes

Related

How to skip Junit for some java classes using mavan?

I have some classes for which I dont have to write junit classes so I want to skip Junit for some Java classes and want to increase Junit code coverage using Maven. For example, I have placed all Java classes in com.test.xxx package so that I can tell them all classes are to be skipped.
You can use a #Disabled Tag to disable a specific Test. If you just have empty test classes, for whatever reason. Delete them.
If you want to fake code coverage for whatever reason, you can create tests and call your services inside the tests, but do not add any assertations... However this is extremly bad practice and I cant really suggest it to you.

How to execute selenium java class files one by one using Eclipse?

Currently working on selenium-java code. i want to execute scripts of selenium java classes one by one using eclipse
for example : i have signup class first and email verification class second
currently i am running code manually means running first class file after that second
i want to execute that file automatically one after another
Please help me
Looks like you are missing testing framework like jUnit / testNg.
Using such framework will allow you to run specific tests, test suites, test classes etc. in desired order and priority, to enable / disable wanted / unwanted tests / test suites etc.

Does TestNG have a test collection functionality similar to pytest --collect-only with hooks?

Pytest provides the ability to run pytest on a test repository using a --collect-only option that simply outputs the tests it finds based on current configurations.
Additionally, there are hooks that can be implemented that affect what happens during various phases of the collection, such as pytest_collection_modifyitems.
I'm wondering if there's an equivalent collection/hook system available for Java tests using TestNG.
TestNG can be instructed to look for all #Test methods within a specific package and everything inside.
But by default, after TestNG discovers the tests, it executes them.
So in order for your use case to be done, you would need to do the following:
Create a testng suite xml file, that refers to the top level package com.foo.bar for e.g., wherein all the test classes are residing inside either com.foo.bar package or inside a sub-package.
Run TestNG with the JVM argument -Dtestng.mode.dryrun=true which causes TestNG to simulate as if the tests were run without actually running them.
Using both these two things, your use case should be satisfied.

Java test management tools/frameworks?

I'm looking for some kind of test (mostly jUnit, but not exclusivelly) management. What I have in mind is a tool that would allow to easily enable/disable individual tests based on configuration (xml file, property file or in DB etc.).
I was thinking that there must be some maven plugin that could do that, or some tool. Can you suggest anything?
There are Maven plugins for JUnit and TestNG that allow you to define which tests to run from the command line (or all).
JUnit allows the creation of test suites. With some care, you can tailor your test suites to match your "to be enabled / disabled" sets of tests.
Failing that, you could wrap the test suite idea with something that generates / references an XML file for configuration (if that's really the path you want to take). Considering that it's all in a Java class, you might find it easier to do by another means (perhaps an properties file or just in-class handling).

Modularizing JMeter tests?

We are looking to migrate our testing framework over to JMeter. We have 50 + test cases, each of them with repeating actions like Logging in and logging out for example. How can I modularize my approach?
What I'm looking for specifically is a "Add test item from file" so that I could for example, add the login code.
We also have things like connectionID's that need to be passed on every request. Is there anyway jMeter can AUTOMATICALLY replace all occurrences of it with a Jmeter variable? Atm the proxy-recorder records the actual connection string, and we have to manually replace that with ${connectionID}. Is there a better way?
This works fine for me.
Make a new thread group at the bottom of the test plan and put a simple controller in it. Inside the simple controller put the code you want to repeat. I use two simple controllers but one is actually a DB test case suite. While keeping whatever is inside the thread group enabled, make sure to put the thread group itself as disabled, or else it will execute again on its own.
Now, in any particular test case, add User Parameters and add a Module Controller. The Module Controller can point to the simple controller section(s) you made before. Have the simple controller with a ${variables} set, then override them here inside the particular test you are running by putting the variable in the User Parameters. Thus you get the different variables and tests with the same suite.
I put a Simple Controller inside the Simple Controller to add lengthy db tests. This ends up as
Thread Group > Simple Controller > Simple Controller > JDBC Request. All are renamed.
You can select different ones in the Module Controller inside the tests. I have about six right now but this gets repeated dozens of times.
This is all with a stock Jmeter 2.3 . If you are in an environment such that you can't install the plugins, this will work fine. I've never tried them
HTH
As far as automatically replacing the connection IDs, there is not, to my knowledge, a way to do that via the GUI. However, the test scripts are simple XML files and so it would be very easy to write a sed or awk script to do that replacement for you.
As far as the "add test file from here" part, in 2.6 (not sure about other versions, not used them) there is a logic controller called "Include Controller" that can load test snippets.There is also the ability to save snippets of test code called "test fragments" to their own .jmx files.
If you start a new test plan, right click on test plan then add -> test fragment -> test fragment this will add the container, then you can add your other requests in and use this chunk inside the aforementioned Include element.
If you are able to use the latest version, or if the prior versions support this, this may be a simpler option than writing your own plugin.
By using below Jmeter elements, we can modularize the test scripts.
Test Fragment
Module Controller
Parameterized Controller
Include Controller
Please check this for more details & examples.
http://www.testautomationguru.com/jmeter-modularizing-test-scripts/
I know 2 options for you:
Module Controller
Parameterized Controller
What I'm looking for specifically is a "Add test item from file" so that I could for example, add the login code.
Sounds like you might want to encapsulate some of that repeated logic in your own custom Samplers or Config Elements. There is a guide to writing plugins to JMeter on the project page.
This is the approach that we have taken on my current team for handling JMeter simulating requests of a custom RPC format.
One thing is you can run the jmeter scripts under "noGUI" model. You can specify the jmeter test scripts to run and put a batch of them into a .bat file. Like:
#echo
JMeter -n -t MyTestPlan1.jmx
JMeter -n -t MyTestPlan2.jmx
Another way I agree with #matt is you can write the plugin to get what your need.

Categories

Resources