0

I wanted to run tests defined by TestNG in parallel.

I have @DataProvider method which contains the list of IDs

@BeforeClass method gets every ID, does some processing and stores the result in the Map. There is one @Test method which uses the values present in Map and performs the validation.

I used the following statement within the xml:

<suite name="My suite" parallel="methods" thread-count="5">

I wanted to run the tests in parallel and the Map computed should not be shared across the thread. The values should be thread specific.

How should I define such a variable and use it only for that thread?

drkthng
  • 6,651
  • 7
  • 33
  • 53
  • So, in essence, you have two maps, not one? – fge Jul 17 '15 at 10:17
  • There are thousands of IDs in the data provider. Why two maps ? – Geethanjali Jul 17 '15 at 10:55
  • Then your question is unclear or you are doing something wrong. A `@BeforeClass` hook will run when the class is first initialized; therefore if you change the values of this map in your tests, this will lead to an undefined behavior. Please post some sample code. – fge Jul 17 '15 at 11:47
  • Yes. It is actually @BeforeMethod. For every ID obtained from DataProvider, BeforeMethod has to be executed and data has to be computed with which Test will run. This has to run in multiple threads – Geethanjali Jul 19 '15 at 05:59
  • Please edit the question with relevant information, then. But most likely what you want here is a `ThreadLocal` – fge Jul 19 '15 at 09:25

0 Answers0