Reputation: 18572
I have JMeter script which tests REST API.
It is configured with Junit Request:
During the test, I am posting a lot of items. I want to clean up DB after test execution. I put appropriate logic to tearDown()
.
However, I found that execution from console doesn't call teaDown()
!
Launching from UI works fine.
Here is implementation for tearDown()
:
@AfterClass
public static void tearDown() throws Exception {
LOG.info("tearDown() called");
deleteRecordingsFromDb();
SCHEDULED_EXECUTOR_SERVICE.shutdown();
if (client != null && !client.isClosed()) {
client.close();
}
minClient = null;
}
Also, be aware that Throughput Shaping Timer is used. And parameter is passed with -Jload-profiles="..."
How to make tearDown() executable from the console?
Upvotes: 0
Views: 686
Reputation: 34526
I think you're making some mistakes:
You want to call a method that you annotated with @AfterClass but you don't have a method annotated with @Test. So JMeter will not even discover your method.
JMeter will automatically call setup (@BeforeClass) and tearDown(@AfterClass) methods within an execution of an method annotated with @Test unless you uncheck them
So if you want to make a cleanup for the whole test, just put your code in a regular JSR223 Sampler using Groovy code for example, no need for JUnit request for that.
See:
http://jmeter.apache.org/usermanual/component_reference.html#JUnit_Request
http://jmeter.apache.org/usermanual/component_reference.html#JSR223_Sampler
Upvotes: 1