How to test JUnit Jupiter (JUnit 5) Extensions

Viewed 512

Is there a way to integration test my JUnit Jupiter extension? Of course I can test a good cases of extension usage, but I would like to test things like:

  • Does it fail tests as expected?
  • Are the correct reports written on test end?

Is there some built in support for this?

2 Answers

There is no explicit Jupiter extension testing framework -- but with version 1.4 there'll be the Platform Test Kit that you may use to execute the Jupiter engine and your extension in one-go and assert the outcome of a test run.

For details see: https://junit.org/junit5/docs/snapshot/user-guide/#testkit and in addition to that documentation, find usages of the Platform Test Kit within the "platform-tests" project of JUnit 5. For example at: https://github.com/junit-team/junit5/blob/master/platform-tests/src/test/java/org/junit/platform/testkit/engine/ExecutionsIntegrationTests.java

You should not perform integration testing for your own extension of Junit. The Junit 5 API is very, very stable and I bet that your extension will work the same for the entire life of Junit 5. Integration testing is useful in a constantly evolving environment, but Junit only ever adds features and never changes them (unless there is a bug).

If you perform integration testing for your own Junit extension, it's like you're testing Junit itself. Why would you test Junit instead of your extension? Let Junit be tested by Junit developers, unless you think you found a bug. But testing Junit for the sake of testing Junit is a waste of your own time, even if unconsciously you think you're only testing your own extension.

So that kind of tests should be done on the long term by getting your users to report issues to you: "Hey, AwesomeExtension works with Junit 5.A.B but not with 5.X.Y", then find out why they say that and if the issue is not with your extension, then report with Junit.

However, make sure that you get your extension... unit-tested.

Related