0

I use selenium WebDriver with junit, ant and jenkins. I set up jenkins to use ant build.xml to run my tests. But currently I run only one tests. In build.xml I set variable which is used in each test. So to run test in Jenkins I set in Targets:

build MyTest1 -Dvariable="value"

I want to run all tests in sequence one after another. I try this:

build MyTest1 -Dvariable="value" MyTest2 -Dvariable="value"

But 2 tests began run in browser at the same time. How can I organize needed sequence. Maybe there are some ways to do it in build.xml? I guess I can create target, in which call targets which runs tests, but how set my variable in that case? I'm new to ant so please advice me solution.

I need to clarify - my tests are independent, I won't run them in some stable sequence. The problem is that tests are running in parallel in browser. I need to run first test and only after it finish - run second test.

khris
  • 4,809
  • 21
  • 64
  • 94
  • I'm sorry, junit, it is just typo – khris Nov 26 '13 at 11:07
  • You can set the ant property to the value which you are passing from command line to a variable ( & note it is immutable ) & have your dependency chain created with your targets : MyTest1 , MyTest2 ... ? – user1587504 Nov 26 '13 at 14:13
  • There is a pretty decent answer in [this thread][1] also. [1]: http://stackoverflow.com/questions/3693626/how-to-run-test-methods-in-specific-order-in-junit4 – djangofan Nov 26 '13 at 15:55

1 Answers1

1

First of all, tests should have little dependencies. In your case, your tests depend on a global variable - try to get rid of it. Use a "configuration" object that you can modify from tests in a safe way and which your application code then uses to configure itself.

Which reduces the problem above to "how do I collect a number of tests" to which the answer is: Use a test suite:

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
   MyTest1.class,
   MyTest2.class
})
public class JunitTestSuite {   
}   
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820