JUnit实战(2) - JUnit核心(使用Suite来组合测试)

本文详细介绍了如何创建并组织Java项目中的测试套件,包括MasterTestSuite、TestSuiteA和TestSuiteB的实现,以及TestCaseA和TestCaseB的具体测试用例。通过使用JUnit框架,展示了如何有效地进行单元测试和集成测试。

创建Java Project项目:ch02-internals

MasterTestSuite.java

package com.manning.junitbook.ch02.internals;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(value = Suite.class)
@SuiteClasses(value = { TestSuiteA.class, TestSuiteB.class })
public class MasterTestSuite {
    
}

TestSuiteA.java

package com.manning.junitbook.ch02.internals;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(value = Suite.class)
@SuiteClasses(value = { TestCaseA.class })
public class TestSuiteA {
    
}

TestSuiteB.java

package com.manning.junitbook.ch02.internals;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(value = Suite.class)
@SuiteClasses(value = { TestCaseB.class })
public class TestSuiteB {
    
}

TestCaseA.java

package com.manning.junitbook.ch02.internals;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class TestCaseA {
    @Test
    public void testA1() {
        assertEquals("Dummy test-case", 1+1, 2);
    }
}

TestCaseB.java

package com.manning.junitbook.ch02.internals;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class TestCaseB {
    @Test
    public void testB1() {
        assertTrue("Dummy test-case", true);
    }
}

注:层级关系Suite-->Suite--TestCase.

pom.xml

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.manning.junitbook</groupId>
        <artifactId>junit-in-action-II</artifactId>
        <version>2.0-SNAPSHOT</version>
    </parent>
    <artifactId>ch02-internals</artifactId>
    
    <packaging>jar</packaging>

    <name>JUnitBook Chapter 2 - JUnit internals</name>
    <url>http://maven.apache.org</url>
</project>

 

转载于:https://www.cnblogs.com/thlzhf/p/4276038.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值