Method call after all tests running in JUnit

I want to create a custom html report for a test run in JUnit. The problem is that you are freeing resources and closing tags after all tests have completed.

I keep one FileChannel open for writing to report. Since there should be a table with a row for each test, and there are hundreds of them, I do not want to open and close the channel for each test. The problem that appears here is the organization of the tests. I have nested packages, so testRunFinished is not an option (applies to a single set, not to all tests, and I saw this question ). TestWatcher will also not help me, since it refers to only one test.

Tools used: maven 3.0.5, ff webdriver, junit 4.11.

I considered two options: 1) open and close channel on each test run 2) rewrite finalize () to close the channel

None of them look pretty ... I have looked through many pages, but I do not have the same problem.

Any more beautiful solutions?

+4
source share
1 answer

Yes, see here ( Before and after package completion in jUnit 4.x ):

@RunWith(Suite.class)
@SuiteClasses({Test1.class, Test2.class})
public class TestSuite {
    @BeforeClass
    public static void setUp() {
        System.out.println("setting up");
    }

    @AfterClass
    public static void tearDown() {
        System.out.println("tearing down");
    }
}
+5
source

Source: https://habr.com/ru/post/1526885/


All Articles