Prev Next

Testing / Junit Interview questions III

When are unit tests garbage collected in Junit?

As per the design, the Test instances tree is built at first pass and the test execution is performed as the second pass.

The test runner holds strong references to all test instances for the duration of the test execution. For instance, in case of a very long test run with many Test instances, none of the tests may be garbage collected until the completion of the entire test run.

Therefore, we need to programmatically free-up resources that are availed or allocated for running a test.. Explicitly setting an object to null in the tearDown() method allows it to be garbage collected before the completion of the entire test run.

More Related questions...

Show more question and Answers...


Comments & Discussions