Pitest with JUnit 4 and 5

441 views
Skip to first unread message

Scott Edwards

unread,
Nov 9, 2020, 4:53:00 AM11/9/20
to PIT Users
Hello, I'm working on a project where the majority of the tests are JUnit 4 tests, with a few newer ones in JUnit 5. Is there a way I can get Pitest to run mutation testing for all the classes, whether they have tests written in JUnit 4 or 5?

Thanks

Marcin Zajączkowski

unread,
Nov 9, 2020, 3:39:21 PM11/9/20
to pitu...@googlegroups.com
Hi. Have you tried to use JUnit (5) Platform to run all your tests? The
new one with JUnit Jupiter and the older with JUnit Vintage. I haven't
tested it, but for PIT all the tests should be recognized as ran with
JUnit 5 and handled with the junit5 plugin.

Marcin

--
https://blog.solidsoft.pl/ - Working code is not enough

Scott Edwards Coll

unread,
Nov 9, 2020, 4:15:13 PM11/9/20
to pitu...@googlegroups.com
Yes, the JUnit tests run fine by themselves - both 4 and 5 will work at the same time. But when I run mutation coverage using pitest it only picks up the JUnit-5 tests when I’ve specified the pitest-junit5-dependency, and only the JUnit-4 tests when I haven’t.

> On 9 Nov 2020, at 20:39, Marcin Zajączkowski <msz...@wp.pl> wrote:
> --
> You received this message because you are subscribed to a topic in the Google Groups "PIT Users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/pitusers/6p3LTJtvBEo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to pitusers+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pitusers/fc5b1c5e-4d41-a3db-959f-c8eaa5cba531%40wp.pl.

Marcin Zajączkowski

unread,
Nov 9, 2020, 5:06:53 PM11/9/20
to pitu...@googlegroups.com
On 2020-11-09 22:15, Scott Edwards Coll wrote:
> Yes, the JUnit tests run fine by themselves - both 4 and 5 will work at the same time. But when I run mutation coverage using pitest it only picks up the JUnit-5 tests when I’ve specified the pitest-junit5-dependency, and only the JUnit-4 tests when I haven’t.

Just to mitigate a risk of mistake, are you sure you use the
junit5-vintage dependency (and in the report or in Idea you see that
JUnit Platform runs it - one subtree for JUnit Jupiter one for JUnit
Vintage)?

If yes, it would be probably good to provide a simple Gradle or Maven
project with 2 tests and report it as a feature request to
https://github.com/pitest/pitest-junit5-plugin to make it easier for the
project maintainers to play with it as an "acceptance" test, as it might
be a limitation of the plugin, e.g. support only for JUnit Jupiter.
However, for instance Spock 2 (internally using JUnit Platform) works
fine with the pitest-junit5 plugin -
https://github.com/szpak/gradle-pitest-plugin/blob/master/src/funcTest/resources/testProjects/junit5spock2/build.gradle
.

Marcin

Scott Edwards Coll

unread,
Nov 10, 2020, 4:29:24 AM11/10/20
to pitu...@googlegroups.com
Yep, both run in the manner you describe. I'll see if I can replicate the behaviour in a sample project and do as you say.
--
You received this message because you are subscribed to a topic in the Google Groups "PIT Users" group.
To unsubscribe from this group and all its topics, send an email to pitusers+u...@googlegroups.com.
Sent from Mailspring
Reply all
Reply to author
Forward
0 new messages