Difference between test suite, test case and test category

我是研究僧i 提交于 2021-02-04 19:52:07

问题


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

But what about categories?


回答1:


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:

  • @Category in JUnit
  • @group annotation in PHPUnit
  • TestCategory in MSTest



回答2:


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.



来源:https://stackoverflow.com/questions/44069595/difference-between-test-suite-test-case-and-test-category

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!