Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (10.2k points)

When I attempt to run the following test in IntelliJ IDEA I get the message:

"!!! JUnit version 3.8 or later expected:"

It should be noted that this is an Android project I am working on in IntelliJ IDEA 9.

public class GameScoreUtilTest {

    @Test

    public void testCalculateResults() throws Exception {

        final Game game = new Game();

        final Player player1 = new Player();

        {

            final PlayedHole playedHole = new PlayedHole();

            playedHole.setScore(1);

            game.getHoleScoreMap().put(player1, playedHole);

        }

        {

            final PlayedHole playedHole = new PlayedHole();

            playedHole.setScore(3);

            game.getHoleScoreMap().put(player1, playedHole);

        }

        final GameResults gameResults = GameScoreUtil.calculateResults(game);

        assertEquals(4, gameResults.getScore());

    }

}

The full stack trace looks like this...

!!! JUnit version 3.8 or later expected:

java.lang.RuntimeException: Stub!

    at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5)

    at junit.textui.TestRunner.<init>(TestRunner.java:54)

    at junit.textui.TestRunner.<init>(TestRunner.java:48)

    at junit.textui.TestRunner.<init>(TestRunner.java:41)

    at com.intellij.rt.execution.junit.JUnitStarter.junitVersionChecks(JUnitStarter.java:152)

    at com.intellij.rt.execution.junit.JUnitStarter.canWorkWithJUnitVersion(JUnitStarter.java:136)

    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:49)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:110)

Process finished with exit code -3

1 Answer

0 votes
by (46k points)
This difficulty happens because the Android Platform (android.jar) already includes JUnit classes. IDEA test runner loads these classes and recognizes that they are from the old JUnit, while you are attempting to use annotated tests which is a feature of the new JUnit, therefore you get the trip from the test runner.

The resolution is simple, open the Project Structure | Modules | Dependencies, and leave the JUnit-4.7.jar up, so that it appears before the Android 1.6 Platform in the classpath. Now the test runner will be pleased as it loads the new JUnit version.

Related questions

0 votes
1 answer
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Oct 13, 2019 in Java by Ritik (3.5k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...