3

I am configuring my own Spring test runner and I try to define test execution order. But I want to change it in the process depending on failure of some test cases. Each test case configuration has it's own id and onFailId that indicates id of the next test to be executed in case of failure. If the test pass, simply the test with the next id is executed. There might be some scenarios when I want to rerun or execute earlier test again.

How can I force this logic, e.g. in test failure listener?

Nilesh
  • 4,137
  • 6
  • 39
  • 53
Danio
  • 1,064
  • 1
  • 11
  • 25
  • 1
    Duplicate question. You may find more information here http://stackoverflow.com/questions/3693626/how-to-run-test-methods-in-specific-order-in-junit4 –  Jul 31 '14 at 16:24
  • Duplicate of this too http://stackoverflow.com/questions/3089151/specifying-an-order-to-junit-4-tests-at-the-method-level-not-class-level – Nilesh Jul 31 '14 at 16:59
  • Those describe setting a fixed order before executing tests. I don't know how can I use these methods to modify order during the process. – Danio Aug 01 '14 at 10:10

1 Answers1

1

I figured out and implemented a solution. Defining a sorting method before running test suite is not enough. All methods mentioned e.g. here How to run test methods in specific order in JUnit4? in junit4 allow setting order before execution only.

I had to overload childrenInvoker method in my runner - that is SpringJUnit4ClassRunner - by default, it calls runChlidren (private method) which runs all children tests in a loop.

If you replace this loop by your own code, you can specify additional logic after each test execution - such as choosing the next test to be run.

Community
  • 1
  • 1
Danio
  • 1,064
  • 1
  • 11
  • 25