Junit 5测试套件
我试图将一个项目从Junit 4迁移到Junit 5.8.2,而Junit-Platform-Suite-API 1.8.2。我们曾经在测试套件中组织测试课程。但是,如果我使用@SeclaTe andation @SelectClasses,则测试跑者根本找不到测试方法。当直接运行特定的测试类时,一切都很好。这发生在Eclipse和Gradle构建中。
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
@Suite
@SelectClasses({
TestA.class
})
public class ImportantTestSuite {
}
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
public class TestA {
@Test
public void reallyImportantTest() {
assertEquals(2, 1 + 1)
}
}
build.gradle看起来像这样
plugins {
id 'application'
}
dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testImplementation 'org.junit.platform:junit-platform-suite-api:1.8.2'
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
}
test {
useJUnitPlatform()
minHeapSize = '1024m'
maxHeapSize = '1024m'
include '**/*ImportantTestSuite*'
ignoreFailures = true
testLogging {
exceptionFormat 'full'
events 'passed', 'skipped', 'failed'
}
}
的想法如何在课堂上组织套房?
:
编辑 答案。据我所知,我正在使用@suite和@SelectClasses而不是跑步者使用该Apporach。
I'm trying to migrate a Project from JUnit 4 to JUnit 5.8.2 with junit-platform-suite-api 1.8.2. We used to organize our test classes in test suites. But if I use the @Suite annotation with @SelectClasses the test runner finds no test methods at all. When running a specific test class directly everything is fine. This happens in eclipse and gradle builds.
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
@Suite
@SelectClasses({
TestA.class
})
public class ImportantTestSuite {
}
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
public class TestA {
@Test
public void reallyImportantTest() {
assertEquals(2, 1 + 1)
}
}
build.gradle looks like this
plugins {
id 'application'
}
dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testImplementation 'org.junit.platform:junit-platform-suite-api:1.8.2'
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
}
test {
useJUnitPlatform()
minHeapSize = '1024m'
maxHeapSize = '1024m'
include '**/*ImportantTestSuite*'
ignoreFailures = true
testLogging {
exceptionFormat 'full'
events 'passed', 'skipped', 'failed'
}
}
Any idea how to organize the suites on class basis?
Edit:
Are test suites considered deprecated in JUnit5?
I already read this answers. As far as I see I'm using that apporach with @Suite and @SelectClasses and not the runner.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
junit-platform-suite-engine缺少...
请参阅: https://junit.org/junit5/junit5/docs/current/current/user-guide/index.html#junit-platform-suite-suite-suite-engine-eengine
The junit-platform-suite-engine was missing...
See: https://junit.org/junit5/docs/current/user-guide/index.html#junit-platform-suite-engine
Eclipse 4.25(Eclipse 2022-09同时释放的一部分)应改善对Junit 5的支持:
Eclipse 4.25 (part of the Eclipse 2022-09 simultaneous release) should improve the support for JUnit 5: