Back to Junit4

ReleaseNotes4.7

doc/ReleaseNotes4.7.html

latest2.2 KB
Original Source

Summary of Changes in version 4.7

Rules

  • Rules allow very flexible addition or redefinition of the behavior of each test method in a test class. Testers can reuse or extend one of the provided Rules below, or write their own.

  • The TemporaryFolder Rule allows creation of files and folders that are guaranteed to be deleted when the test method finishes (whether it passes or fails):

  • ExternalResource is a base class for Rules (like TemporaryFolder) that set up an external resource before a test (a file, socket, server, database connection, etc.), and guarantee to tear it down afterward:

  • The ErrorCollector Rule allows execution of a test to continue after the first problem is found (for example, to collect all the incorrect rows in a table, and report them all at once):

  • Verifier is a base class for Rules like ErrorCollector, which can turn otherwise passing test methods into failing tests if a verification check is failed

  • TestWatchman is a base class for Rules that take note of the testing action, without modifying it. For example, this class will keep a log of each passing and failing test:

  • The TestName Rule makes the current test name available inside test methods:

  • The Timeout Rule applies the same timeout to all test methods in a class:

  • The ExpectedException Rule allows in-test specification of expected exception types and messages:

Timeouts

  • Tests that time out now show the stack trace of the test thread.

Matchers

  • Due to typing incompatibilities, JUnit is still including the 1.1 release of hamcrest. This is not a change from 4.6, but is a change from pre-beta releases of 4.7. Due to this incompatibility, tests using Hamcrest 1.2 must still use the MatcherAssert.assertThat method from Hamcrest, not Assert.assertThat from JUnit.

Docs

  • Javadocs now link to online JDK javadocs (bug 2090230)
  • Parameterized runner javadocs improved (bug 2186792)
  • Fixed Javadoc code sample for AfterClass (2126279)
  • Fixed Javadoc for assertArraysEqual(float[], float[])

Bug fixes

  • Fixed: BaseTestRunner.getTest() requires class to extend TestCase (1812200)
  • Fixed: Suite does not allow for inheritance in annotations (2783118)
  • Fixed: ParallelComputer skipped tests that took longer than 2 seconds