java中标签分组的思想_java – 如何对大量JUnit测试进行分组/分类

假设我对这个问题的理解是正确的,实际上可以使用JUnit来完成.下面的代码与JUnit 4.11一起使用,并允许我们将所有测试分为两类:“未分类”和集成.

IntegrationTestSuite.java

/**

* A custom JUnit runner that executes all tests from the classpath that

* match the ca.vtesc.portfolio.*Test pattern

* and marked with @Category(IntegrationTestCategory.class)

* annotation.

*/

@RunWith(Categories.class)

@IncludeCategory(IntegrationTestCategory.class)

@Suite.SuiteClasses( { IntegrationTests.class })

public class IntegrationTestSuite {

}

@RunWith(ClasspathSuite.class)

@ClasspathSuite.ClassnameFilters({ "ca.vtesc.portfolio.*Test" })

class IntegrationTests {

}

UnitTestSuite.java

/**

* A custom JUnit runner that executes all tests from the classpath that match

* ca.vtesc.portfolio.*Test pattern.

*

* Classes and methods that are annotated with the

* @Category(IntegrationTestCategory.class) category are

* excluded.

*/

@RunWith(Categories.class)

@ExcludeCategory(IntegrationTestCategory.class)

@Suite.SuiteClasses( { UnitTests.class })

public class UnitTestSuite {

}

@RunWith(ClasspathSuite.class)

@ClasspathSuite.ClassnameFilters({ "ca.vtesc.portfolio.*Test" })

class UnitTests {

}

IntegrationTestCategory.java

/**

* A marker interface for running integration tests.

*/

public interface IntegrationTestCategory {

}

下面的第一个示例测试未使用任何类别进行注释,因此在运行UnitTestSuite时将包括其所有测试方法,并在运行IntegrationTestSuite时将其排除.

public class OptionsServiceImplTest {

@Test

public void testOptionAssignment() {

// actual test code

}

}

下一个示例在类级别上标记为Integration测试,这意味着在运行UnitTestSuite并将其包含在IntegrationTestSuite中时,将排除其测试方法:

@Category(IntegrationTestCategory.class)

public class PortfolioServiceImplTest {

@Test

public void testTransfer() {

// actual test code

}

@Test

public void testQuote() {

}

}

第三个示例演示了一个测试类,其中一个方法没有注释,另一个标记为Integration类.

public class MarginServiceImplTest {

@Test

public void testPayment() {

}

@Test

@Category(IntegrationTestCategory.class)

public void testCall() {

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值