Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does new JUnit 4.8.1 @Category render test suites almost obsolete?

Given question 'How to run all tests belonging to a certain Category?' and the answer would the following approach be better for test organization?

  1. define master test suite that contains all tests (e.g. using ClasspathSuite)
  2. design sufficient set of JUnit categories (sufficient means that every desirable collection of tests is identifiable by one or more categories)
  3. qualify each test with relevant category(ies)
  4. define targeted test suites based on master test suite and set of categories

Example:

  • identify categories for speed (slow, fast), dependencies (mock, database, integration, etc.), function (fill in applicable categories), domain (fill in applicable categories), etc.
  • demand that each test is properly qualified (tagged) with relevant set of categories.
  • create master test suite using ClasspathSuite (all tests found in classpath)
  • create targeted suites by qualifying master test suite with categories, e.g. mock test suite, fast database test suite, slow integration for domain X test suite, etc.

My question is more like soliciting approval rate for such approach vs. classic test suite approach. One unbeatable benefit is that every new test is immediately contained by relevant suites with no suite maintenance. One concern is proper categorization of each test.

like image 728
topchef Avatar asked Apr 23 '10 11:04

topchef


People also ask

Is Suite test supported by JUnit?

In JUnit, both @RunWith and @Suite annotations are used to run the suite tests.

What is the difference between a test case and a test suite?

A test case answers the question: What am I going to test? You develop test cases to define the things that you must validate to ensure that the system is working correctly and is built with a high level of quality. A test suite is a collection of test cases that are grouped for test execution purposes.


1 Answers

One of the trade-off you have to consider is IMHO that categories are defined within the tests and suites are defined outside. This means, that when you use suites, you know which tests will be run, but when using categories, you do not know unless you inspect tests or simple run them. At the same time, when you look at the test using test suites you do not know in which suite it is contained, unless checking your suites, but using categories, you see it immidiatly.

like image 56
Gabriel Ščerbák Avatar answered Nov 07 '22 03:11

Gabriel Ščerbák