testng: running parallel=methods while there is an instance variable shared between methods
Searched a lot for a vivid answer about testng behavior and didn’t find until now...
if I run my tests/suite with parallel=“methods” And One of my tests has 3 methods (@Test methods) that the 3 of them Are sharing the same instance object/instance variable (not static!). will it be thread safe? testng totally seperates the methods so each method see its own instance variable of the shared one? I mean, testng will create a seperated class instance for each method and run?
I assume you're using JUnit, and I assume by "instance variable (not static!)" you simply mean "test fixture class member" (or maybe you even mean "test case local variable").
Then the answer is "No - they will not share the same instance of the same variable". The JUnit runner will create different class instances for each test case and each test fixture. Each instance will run concurrently, but the class members will be separate and independent of each other.