title: Selenium + JUnit: test order/flow?
body: <p>I am using Selenium to test my java web app's html pages (JSPs actually). My web app requires a flow to access each pages (it is a small online game web app), as in: to get to page B you'd need to go to page A, enter some text and press a button to get to page B. Obviously I already have some tests to verify that page A is working properly.</p>
  
  <p>I would like to be able to write more tests in order to check that after the tests for page A run I'll get my tests for page B running (and so on for the rest of the app). So in short: define some order in my tests somehow.</p>
  
  <p>After doing lots of reading about testing in the last few days, I cannot find anything interesting on this specific subject. Hence I'm asking for advice now.</p>
  
  <p>Possible Solutions I have identified:</p>
  
  <ol>
  <li><p>Define (in the same test class) test methods for page A, then test methods for test B. Then order the execution of the test methods. But we know JUnit (but TestNG does) does not allow test methods execution ordering, see <a href="https://stackoverflow.com/questions/8518314/selenium-junit-tests-how-do-i-run-tests-within-a-test-in-sequential-order">SO question selenium-junit-tests-how-do-i-run-tests-within-a-test-in-sequential-order</a></p></li>
  <li><p>Grouping all the tests (for page A, page B, &amp; so on) under one test method. But I've read it's bad, see <a href="https://stackoverflow.com/questions/6252187/junit-one-test-case-per-method-or-multiple-test-cases-per-method">SO question: junit-one-test-case-per-method-or-multiple-test-cases-per-method</a>. Is it that bad when doing selenium test? I've seen some code doing it so I assume it may not be.</p></li>
  <li><p>Grouping all the tests (for page A, page B, &amp; so on) under one test method but use the JUnit's ErrorCollector class: <a href="http://www.catosplace.net/blogs/personal/2009/09/04/junit-4-7-error-collector-core-rule/" rel="nofollow noreferrer">ErrorCollector</a> allows you to execute ordered checks in the same method and yields a specific error message if one fails BUT let the method (hence the checks) running until the end. This solution seems too "brutal" to me.</p></li>
  <li><p>Use JUnit's TestSuite class: it runs test listed in the suite in the order test classes are defined in the suite. So that would involve having independent test methods to test page A in a test class (let's say TestA), then all the test methods to test page B in a test class (let's say TestB), and so on. Then insert those in a test suite such as @SuiteClasses( {TestA.class, TestB.class, TestC.class, ...} )</p></li>
  <li><p>Use <a href="http://www.junit.org/apidocs/junit/framework/TestSuite.html" rel="nofollow noreferrer">JUnit's TestSuite class</a> in combination with JUnit's ErrorCollector class. Oh well, since we can, you may want to Group test per page in different classes, &amp; on top of that group page tests "zones" using ErrorCollector. This solution may be very usefull if you have a very dense web page or other reasons.</p></li>
  <li><p>Quite radical: Use another tool such as <a href="http://testng.org/" rel="nofollow noreferrer">TestNG</a> to have access to features such as test method ordering.</p></li>
  </ol>
  
  <p>Note: I imagine some would recommend the last solution (migrate to TestNG) but I'd like to hear other ideas/opinions tied to JUnit too. As in, if I'm working in a team that is not able (for some reason) to migrate to another testing framework, then how would they address this test ordering issue?</p>