问题
Is it possible to exclude an individual test from @BeforeEach
in JUnit5
?
Kindly guide me for this.
Thank you
回答1:
You can move the tests that require the before-each behaviour into an inner ˋ@Nested´ subclass and put the before-each method there.
回答2:
You could use TestInfo and write this condition by inspecting the test name:
@BeforeEach
void init(TestInfo info) {
if (info.getDisplayName().equals("mySpecialTestName") {
return; // skip @BeforeEach in mySpecialTestName test
}
}
but it would be cleaner to move the tests that don't need @BeforeEach
to a separate class.
来源:https://stackoverflow.com/questions/58772186/can-i-exclude-an-individual-test-from-beforeeach-in-junit5