catch32
catch32

Reputation: 18572

tearDown() is not called after script execution from console

I have JMeter script which tests REST API.

It is configured with Junit Request:

enter image description here

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

Answers (1)

UBIK LOAD PACK
UBIK LOAD PACK

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:

Upvotes: 1

Related Questions