Skip to content

Commit 864f676

Browse files
committed
Fix test leak detection in JUnit tests
While working on #2685 and specifically trying to verify that change fixes the comment below \* I realized that a migration step was missed changing the suites from JUnit4 to JUnit5. On JUnit5 the `@BeforeAll` and `@AfterAll` only apply to the tests in the class itself, not to `@SelectClasses` too. Instead JUnit5 provides `@BeforeSuite` and `@AfterSuite` \* this comment: > For some reason, printing to System.err in JUnit test has no effect
1 parent e9a8f5f commit 864f676

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/AllNonBrowserTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import java.util.List;
1919

2020
import org.eclipse.swt.graphics.Resource;
21-
import org.junit.jupiter.api.AfterAll;
22-
import org.junit.jupiter.api.BeforeAll;
21+
import org.junit.platform.suite.api.AfterSuite;
22+
import org.junit.platform.suite.api.BeforeSuite;
2323
import org.junit.platform.suite.api.SelectClasses;
2424
import org.junit.platform.suite.api.Suite;
2525

@@ -79,8 +79,8 @@
7979
public class AllNonBrowserTests {
8080
private static List<Error> leakedResources;
8181

82-
@BeforeAll
83-
public static void beforeClass() {
82+
@BeforeSuite
83+
public static void beforeSuite() {
8484
// Set up ResourceTracked to detect any leaks
8585
leakedResources = new ArrayList<> ();
8686
Resource.setNonDisposeHandler (error -> {
@@ -93,11 +93,11 @@ public static void beforeClass() {
9393

9494
/*
9595
* It would be easier to understand if errors here were reported
96-
* through a test and not through @AfterClass, but this is a
96+
* through a test and not through @AfterSuite, but this is a
9797
* suite class and not a test class, so it can't have tests.
9898
*/
99-
@AfterAll
100-
public static void afterClass() {
99+
@AfterSuite
100+
public static void afterSuite() {
101101
// Run GC in order do detect any outstanding leaks
102102
System.gc ();
103103
// And wait a bit to let Resource.ResourceTracker, that is

0 commit comments

Comments
 (0)