views:

332

answers:

2

Hi, I am running hundreds of tests against a large publishing system and would like to paralellize the tests using TestNG. However, I cannot find any easy way of doing this. Each test case instanciates an instance of this publisher, send some messages, wait for those messages to be published, then dump out the contents of the publish queues and compare against expected outcome. Doing this with so many tests (even if I paralellize using threads, still takes a very long time to complete (1 day or more)).

We've found that in testing this sort of system, it's best to start up system once, run all tests to send their messages, wait for publish to do its thing, dump all outputs, and match outputs with tests and verify. For example, instead of the following:

@Test
public void testRule1() {
  Publisher pub = new Publisher();
  pub.sendRule(new Rule("test1-a"));
  sleep(10); // wait 10 seconds
  pub.dumpRules();
  verifyRule("test1-a");
}

We wanted to do something like the following:

@Test
public void testRule1(bool sendMode) {
  if(sendMode) {
    this.pub.sendRule(new Rule("test1-a"));
  }
  else {
    verifyRule("test1-a");
  }
}

Where you have a dataProvider run through all the tests with sendMode = true and then perform dumpAllRules() followed by running through all of the tests again with sendMode = false. The problem is, TestNG calls the same method twice, once with sendMode = true followed by sendMode = false. Is there anyway to accomplish this in TestNG?

Thanks!

A: 

Can you post your entire class, including the @DataProvider? What you are trying to do should work, you must have overlooked something.

Cedric Beust
A: 

Hi Cedric, What I'm trying to accomplish is:

  1. Perform initialization before all test suites
  2. Run configure (to configure environment) before each test suite
  3. Run all tests in suite (execute mode)
  4. Run services and do batching work (combine output files, send to service, dump outputs)
  5. Run all tests in suite (again, but check mode now)
  6. Perform cleanup work

Currently, dataProvider seems to be running each individual test against all data like: Test1(true), Test1(false), Test2(true), Test2(false), ... Is there a way to have it run the data against all tests?

Mohamed Nuur
After fiddling around with the API, I found that I can achieve the same results by implementing the IMethodInterceptor listener. However, I am having problems inserting non-test method (PerformBatching) between the first half and second half. For those who are interested: http://pastebin.com/m37dac727
Mohamed Nuur