4

What is the difference between test suite, test case and test category. I found a partial answer here

But what about categories?

Community
  • 1
  • 1
Oleh
  • 71
  • 1
  • 1
  • 3

2 Answers2

9

Test case is a set of test inputs, execution conditions, and expected results developed to test a particular execution path. Usually, the case is a single method.

Test suite is a list of related test cases. Suite may contain common initialization and cleanup routines specific to the cases included.

Test category/group is a way to tag individual test cases and assign them to categories. With categories, you don't need to maintain a list of test cases.

Testing framework usually provides a way to specify which categories to include or exclude from a given test run. This allows you to mark related test cases across different test suites. This is useful when you need to disable/enable cases that have common dependencies (API, library, system, etc.) or attributes (slow, fast cases).

As far as I can understand, test group and test category are different names for the same concept used in different frameworks:

default locale
  • 13,035
  • 13
  • 56
  • 62
  • 2
    Veeeery nice answer. – GhostCat May 19 '17 at 13:21
  • Nit: A test case should not be written to "test a particular execution path." It should be written to test a particular _requirement_, ideally, without any knowledge of the implementation. If your coverage testing shows that your tests are not hitting all the code paths, then the test suite is incomplete (doesn't test all of the requirements), the code has unnecessary code paths, or the specification was missing some requirements. – Adrian McCarthy Aug 06 '21 at 22:09
1

Test Categories is like a sub Test Suite. Take this documentation by example. One a class file, you will have multiple test cases. A Test Suite is a grouping of Test classes that you want to run. A Test Category is a sub grouping of Test Cases. You could put a annotation at some test cases in your class file, and create to test suite pointing to the same test class, but filtering one of the suites to test only some categories. Example from documentation:

public interface FastTests { /* category marker */ }
public interface SlowTests { /* category marker */ }

public class A {
  @Test
  public void a() {
    fail();
  }

  @Category(SlowTests.class)
  @Test
  public void b() {
  }
}

@Category({SlowTests.class, FastTests.class})
public class B {
  @Test
  public void c() {

  }
}

@RunWith(Categories.class)
@IncludeCategory(SlowTests.class)
@SuiteClasses( { A.class, B.class }) // Note that Categories is a kind of Suite
public class SlowTestSuite {
  // Will run A.b and B.c, but not A.a
}

@RunWith(Categories.class)
@IncludeCategory(SlowTests.class)
@ExcludeCategory(FastTests.class)
@SuiteClasses( { A.class, B.class }) // Note that Categories is a kind of Suite
public class SlowTestSuite {
  // Will run A.b, but not A.a or B.c
}

Notice that both Test Suite points to the same test classes, but they will run different test cases.

Bruno
  • 2,889
  • 1
  • 18
  • 25