3

I know that, in test automation, we have to avoid sequential test-cases.So, the order of running the test-cases are not important.

I believe in some cases the sequential test-cases is unavoidable:

1.Consider a scenario which a user needs to take some previous steps in order to complete a final goal. For example, a user needs to be logged in, so that he can purchase.

   Given User is logged in
   When  User adds an item into its basket
   And   User Complete his purchase
   Then  He receives an Email

So, in above scenario, each part (Given, When, And, or Then) are seperate testcases. But still the order of testcase is crucial.

2.Also, Junit team provides a method called @FixMethodOrder(MethodSorters.NAME_ASCENDING) for such usage, but i am not sure when we are allowed to use this?

So, how do you write independent test-cases in end-2-end testing?

Sal-laS
  • 11,016
  • 25
  • 99
  • 169

3 Answers3

2

Tests are meant to be atomic, in the sense that they should NOT rely on a status that was generated by a previous test. That's why sequential test-cases should be avoided. In case any part of the sequence fails, then the rest of the tests fail, so it really doesn't make much sense to have them sepparate (they could be just one test).

If you need preconditions on your tests you can include them in: 1) before all tests, 2) at start of the test suite, 3) before your specific test, 4) inside your specific test. No matter where/when this is done, the important thing is that you assume that all that's needed to generate that status works as expected, so you just focus on what you are testing.

Now, if you want to test a complete flow of a system, I would recommend you to put that inside one unique test. In case there are variations, then you would have multiple tests.

Let's say for example that you want to test D, but D needs C, and then C needs B, and finally B needs A; one strategy would be to generate a test in which you would do A->B->C->D. Another strategy is to generate multiple tests in which you test the individual steps: test 1 does A; test 2 does A->B (but doesn't care if A is ok); test 3 does A->B->C (but doesn't care if A and B are ok); and so on. Which strategy to use would depend on your goals and the size of the scenario. I personally prefer the second option for big things, and the first one for simple/short ones.

Alexis
  • 443
  • 4
  • 11
0

The espresso UI test framework allows to implement such core-user-journey scenarii.

If you want unit tests, then you should set the expected preconditions at the beginning of each.

rds
  • 26,253
  • 19
  • 107
  • 134
0

The saying of "avoid sequential test cases" only apply to unit tests. And that is where Junit and mockito shine. In these cases, we are only worried about a unit correctness. We don't care about other units fail or pass or whatever, we will mock other unit behaviors, so that we can focus on testing exact behaviors of current test.

The case you described don't fall into this category. In your case, you need an integration test suite since you need to test end to end flow. You can use the following tools for integration test.

  • Cucumber
  • Soap UI Test
  • Serenity
  • etc
FranXho
  • 736
  • 7
  • 18