I'm trying to do some stress tests on an API with JMeter. I have two environments (QA and production) and I want to set up QA's database before running JMeter tests.
I can't use JDBC or MongoDB configuration elements because it's a cloud database (DynamoDB - AmazonWS). I thought about using raw requests with API-token to AmazonWS's API but I'd prefer to use a Java class I already have (a class that create-delete queries to cloud DB) but it has Spring dependencies.
I know that with JMeter I can run some Java code but I don't know how to run classes with Spring dependencies like a BeanFactoryPostProcessor.
Any ideas?
I believe the best option would be to use
setUp Thread Group with 1 virtual user and 1 iteration
OS Process Sampler to execute your class (see How to execute a java .class from the command line for example)
Running class from JMeter using i.e. JSR223 Sampler is also possible but you will need to
have all the dependencies in JMeter's classpath
ensure that there are no conflicts between JMeter and your class dependency libraries
Related
I created a project using cucumber to perform e2e tests of various apis I consume. I would like to know if I can run these tests through endpoints to further automate the application that was created.
That way I would be able to upload this app and would not need to keep calling locally.
You can do that if you create a Rest API with a get method which executes the test runner when called.
How to run cucumber feature file from java code not from JUnit Runner
But I don't recommend you to do that since what you are trying to achieve seems to me similar to a pipeline definition.
If you're in touch with the developers of these APIs, you can speak with them about including your test cases in their pipeline, since they probably have one in place.
If, for some reason, you still want to trigger your tests remotely and set it up by your own, I would recommend you to start reading about Jenkins. You can host it on any machine and run your tests from there, accessing from any machine to your jenkins instance:
https://www.softwaretestinghelp.com/cucumber-jenkins-tutorial/
If your code is hosted in any platform like github or gitlab, they already have its own way of creating pipelines and you can use it to run your tests. Read about Gitlab pipelines or Github actions.
There is a library built by our company that is used as an external dependency by the other project we're currently creating tests for (Component Tests, to be more precise). Our goal is thus to let the code flow as deep as possible in all the classes of the pom.xml dependencies, but without requiring network calls.
We want to mock all external dependencies, and do not want to have to modify or fork those libraries from our company.
That library makes calls to an Oracle database using a JNDI connection.
The project runs on Tomcat, and the context.xml sets up the JNDI connection. We initially wanted to simply inject a H2 connection in there instead, but H2 isn't directly compatible with Oracle and the amount of work to achieve that is too big. There is a stored procedure that would need to be translated into a Java function (for the needs of H2 compatibility), among other things.
Is it possible to somehow intercept the calls made to the database, and return something we'd decide instead?
Solutions we're looking into, but haven't yet understood how to make it work:
Something similar to how MockServer/WireMock work.
Figuring out how to set up a proxy.
Somehow injecting a different class than the one that actually calls the database.
We use Java 8, Spring 5 with XML configuration of beans, and Maven Cargo to start the Tomcat 8. The library uses Java 8, Spring 4, and the classes establishing connections to the database are not Beans.
EDIT:
More context on our testing set up.
The project has 2 modules: one for the service itself (it contains the SOAP endpoints), and one for the component-tests.
The service one isn't started with a public static void main (i.e. not even through Spring Boot context launcher).
The test one starts the test suite through a TestNg class that launches the Cucumber runner.
Thus, to test the service, we trigger a Maven Cargo to build the service and deploy in an embedded Tomcat, injecting our test-specific context.xml file. Then, subsequently we launch the CucumberRunner which itself ends up calling the endpoints for the tests.
I know there is remote debugging but I want to go one step further: I would like to run tests in my eclipse that are run within another JVM - i.e. have access to static fields, resources, instances, etc from that JVM.
More specifically: I have an Apache server running locally on my machine and I would like to execute tests as if they were running natively in that very server.
Currently, I implemented my own JUnit test runner that runs within that server/JVM and creates test report XMLs that are written to a folder that I can inspect. But that's a bit bothersome so I would like to be able to run them directly with a mouseclick from eclipse and have them presented there nicely in the JUnit view.
So my question is:
Is there a way to run (not debug) code from eclipse within another JVM?
If so - is this also possible with tests, i.e. run and check the test reports with the JUnit view?
A presume that you are talking about an Apache Tomcat server. (Running unit tests within an arbitrary Apache server doesn't make a lot of sense.)
A Google search didn't yield a lot of leads, but I did come across this:
JUnit-Tomcat: No Mocking Just Testing
Be aware that the source code in the code in the downloadable hasn't been updated since 2006. Apparently doesn't support JUnit 4.0, and it was developed for Tomcat 5.5.
Another option would be to use an embedded Tomcat server within your unit tests; e.g.
https://github.com/mjeanroy/junit-servers
Note: this is not a recommendation.
I have some selenium code which repeats in every JMX I have, how can I create a jar of that and use it in JMeter web driver sampler? I am using Beanshell language in web driver sampler.
For example, if I need to use login and logout in every Jmx of web driver sampler, and now I am repeating it in every JMX. How do I keep those login and logout script somewhere and use that. Keeping as jars would be fine, but how can I do it in jMeter?
Given the .jar containing your functions to perform login/logout will be present in JMeter Classpath you should be able to normally using import statement or equivalent call your functions from the WebDriver Sampler code.
One point: don't use java language as it is not real Java, it is Beanshell interpreter which has limited support of Java features and not very good performance. Since JMeter 3.1 it is recommended to use groovy for any scripting purposes so consider migrating on next available opportunity. Most likely you won't have to change your code.
Also be aware that there is a built-in mechanism in JMeter which helps you to avoid code duplication: Module Controller so instead of having .jars you can have separate WebDriver Sampler instances which will be doing common tasks like login/logout and you will be able to call them via Module Controller where required.
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