I am using ExecutorService to run parallel junit tests. Each test uses a random number generator to identify itself and run independent of the other tests. My scenario is like this
- Test 1 Add new users into the system
- Test 2 Search for users with certain characteristics in the system
- Test 2.1 Select one of the searched users, and send a request
- Test 3 Now use identity from Test 1, and check if there is a request pending. But this test cannot run until 1 and 2 have run. Also they need some data from test1.
I know I can use public static variables to save and restore the data from test1. Any ideas on doing this neatly. Dont want to create a bad impression 1st day at work.
Sample Code below
public class TestCases {
static ExecutorService exe ;
public static void main(String[] args) throws Throwable {
test1() ;
test2() ;
test3() ;
}
public static void test1() {
exe = Executors.newCachedThreadPool() ;
for (int i = 0 ; i < 10 ; i++) {
Test1 test1 = new Test1() ;
exe.execute(test1) ;
}
exe.shutdown() ;
while(!exe.isShutDown()) {
}
}
//same for test2 and test3
}
One way to do this would be to merge Test1 and Test2 as a subset of Test3. Infact all these together can be a Test4. This way you will be testing only 1 particular scenario. I suggest that you think in a way to create scenario based testing.