在Gradle中对于JUnit 5测试的配置,可以通过build.gradle文件的test.task的systemPropertyEntries来添加Key-Value对。然后在测试类中使用@BeforeAll
和@BeforeEach
注释和TestInstance(Instance.Lifecycle.PER_CLASS)
注释来引用系统属性。
示例代码如下:
build.gradle
test {
useJUnitPlatform()
systemProperty 'myProperty', 'myValue'
}
Test class
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class YourTestClass {
@BeforeAll
fun setUp() {
val myProperty = System.getProperty("myProperty")
//do something with myProperty
}
@BeforeEach
fun beforeEach() {
val myProperty = System.getProperty("myProperty")
//do something with myProperty
}
@Test
fun yourTest1() {
val myProperty = System.getProperty("myProperty")
//do something with myProperty
}
@Test
fun yourTest2() {
val myProperty = System.getProperty("myProperty")
//do something with myProperty
}
}
上一篇:ACCESS更新语句中的子查询