简体   繁体   中英

Which structure to use with JUNIT test?

I have a Number of tests. Each test contains different commands verify() and command(). The order and number of times I need to check these vary though depending on the test. How can I structure this in a convenient way. I have been playing with Suites and Categories but can´t find a good solution. in the JUNIT GUI I would like to see the Testname and bellow it the teststeps command or verify. Any ideas?

I have found that with maven and modern IDEs, the usefulness of test suites is not all that apparent.

Maven will run all your tests by default; and any IDE will allow you to run all your tests or select tests to run, by package, for example. I generally find that creating tests classes within different packages is all the organization I every really utilize.

It worries me that you say the "order and number" of times you need to test vary. I am not clear on exactly what you mean, but if you mean that in order for a test to pass, it is dependent on the order (and times) that other tests execute, then you need to re-architecture your tests. (Particularly in the case of unit tests.)

No test should ever depend on another test. Execution order is not guaranteed, and may execute differently in different environments, or could even be executed in parallel.

Look at @Before, @After, @BeforeClass, @AfterClass ( http://junit.sourceforge.net/doc/faq/faq.htm#organize_3 ) for more info on initialization of tests. I'm not sure if that is the solution to your problem, though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM