4

I want to create custom html report for test run in JUnit. Problem I have is releasing resources and closing tags after all tests are done.

I keep one FileChannel opened for writing to report. Since it should be table with row for each test and there are hundreds of them, I don't want to open and close the channel for each test. Problem that appears here is tests organization - I have nested suites, so testRunFinished is not an option (refers to single suite, not all tests, and I saw this question). TestWatcher also will not help me, since it refers to single test only.

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

I was considering two options: 1) opening and closing channel on each test run 2) overwriting finalize() to make it close the channel

None of them seems pretty... I've searched through many pages, but nobody seems to have the same problem I have.

Any prettier solutions?

Community
  • 1
  • 1
Olek Olkuski
  • 93
  • 2
  • 8
  • A clean **TestNG** solution can be found here: http://stackoverflow.com/a/26381858/1857897 – dedek Jul 15 '15 at 06:53

1 Answers1

5

Yes, see here (Before and After Suite execution hook 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");
    }
}
Community
  • 1
  • 1
Smutje
  • 17,733
  • 4
  • 24
  • 41
  • 1
    Okay, but that requires each 'master suite' to have a method annotated as @AfterClass. Is there more universal solution? – Olek Olkuski Feb 14 '14 at 08:03
  • How about creating a single big test suite for dedicated HTML reporting and using the smaller test suites only for "normal" testing? – Smutje Feb 14 '14 at 08:18
  • That's changing business requirements, but might be the only option... And actually I didn't think about that, so thank You :) – Olek Olkuski Feb 14 '14 at 09:57