简介
通过java annotations(注解)形式将TestRule或TestRule子类的实例添加到测试类中,来扩展各种测试功能。
环境
文件目录
.
├── main
│ ├── java
│ └── resources
└── test
├── java
│ └── example
│ ├── TestTemporaryFolder.java
│ └── TestTestName.java
└── resources
build.gradle
group 'example'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'junit:junit:4.12'
}
test {
testLogging.showStandardStreams = true
}
Rule - TestName
package example;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.Description;
import static org.junit.Assert.assertEquals;
public class TestTestName
{
@Rule
public TestName testName = n