码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-02-05 23:07:07      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:

创建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>

 

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

标签:

原文地址:http://www.cnblogs.com/thlzhf/p/4276038.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!