0

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?

catch23
  • 17,519
  • 42
  • 144
  • 217
  • how do you run via console? and does the teardown never gets executed using the command line? – Naman Sep 01 '17 at 17:38
  • it may sound trivial or even slightly silly - but are you sure you run your tests in non-gui on the SAME JMeter instance as you do in GUI mode? – Yuri G Sep 01 '17 at 18:12
  • @Yuri I definitely sure about it.JMeter is exactly the same. Project is packed to one fat jar and loaded to `/jmeter-home/lib/ext/junit`. However, on UI mode I run without shaping timer. I am using loops counter. – catch23 Sep 01 '17 at 21:55
  • @nullpointer I can post full command later. For now it is like `-jar /jmeter-home/bin/jmeter.jar -J... -n -t my-load.jmx`. Looks like yes, it is always skipped. Because DB is over loaded. – catch23 Sep 01 '17 at 21:57

1 Answers1

1

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:

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
  • Screen shot contains only teardown thread group. Of course suite has bunch of tests, and setUp(). Problem is that I have all stuff, like BeforeClass, AfterClass and Test. I see at log that set Up() is called, whereas tearDown() is skipped. – catch23 Sep 01 '17 at 21:52
  • Hello, my answer is still valid after your comment – UBIK LOAD PACK Sep 02 '17 at 06:24
  • I will try it on Monday, and let you know the result. I want to add that `setUp()` I am using for initialization for Concurrent queue during posting new items they are also stored in a queue. When `tearDown` is called I am going through all queue and deleting them. With your variant, it wouldn't be so easy. – catch23 Sep 02 '17 at 17:33