-1

Each of my Junit test cases will have multiple scenarios and an ETL process(takes 20 min) has to be run for verification between each scenario. Suppose i have a class with 4 Junit tests in the format:

  • First test - one scenario
  • Second Test - two scenarios
  • Third Test - three scenarios
  • Fourth Test - four scenarios

Is it possible to run the first scenario alone on all the test methods, hold the session somewhere then returning back to the class to run the second scenarios if available and so on. I would just like to know if this is possible using Junit. I searched in few places and i didn't find any luck.

Paul
  • 18,243
  • 13
  • 70
  • 92
Appunu
  • 19
  • 3
  • it isn't clear to me what you're asking for, are you wanting to execute the first test for all four scenarios, then the second test for three scenarios, third test for two and last test for one? – ninesided Jan 06 '12 at 05:35
  • @Paul - ETL stands for "Extract, Transform, Load", it's a process used to migrate data or interface between systems. – ninesided Jan 06 '12 at 05:37
  • 2
    Your question is quite vague. Can you please put some pseudo code ? – Santosh Jan 06 '12 at 05:37

3 Answers3

0

No. The JUnit FAQ says, "The ordering of test-method invocations is not guaranteed..." See also How to run test methods in spec order in JUnit4?

Another hindrance to your plan as I understand it is that JUnit instantiates a new instance of the test class for each method in the class. (Here is the explanation why) Each of your scenarios will run in a different instance of the test class.

Your question wasn't very clear; perhaps if you gave more detail about what you're trying to do you'll get some suggestions.

Community
  • 1
  • 1
Paul
  • 18,243
  • 13
  • 70
  • 92
0

If you're using a database, can you have four databases?

There isn't anything specific in JUnit for saving/restoring sessions, however, you could look at categories to run only specific tests on the CI server.

Matthew Farwell
  • 58,043
  • 17
  • 119
  • 166
0

If at runtime you can tell whether a certain scenario is applicable / available, you can use conditional (re)runs as many times as there are scenarios:

@Before
public void seeIfScenarioIsApplicable() {

   org.junit.Assume.assumeTrue( isScenarioIsApplicable( ... ) );       
}

@Test 
first (){ // do magic }

@Test 
second (){ // do magic }

@Test 
third (){ // do magic }

@Test 
fourth (){ // do magic }

In case "isScenarioIsApplicable" returns false, the test methods are skipped.

tolitius
  • 20,699
  • 5
  • 65
  • 78