Eclipse JUnit - possible causes of seeing “initializationError” in Eclipse window

后端 未结 25 1177
情深已故
情深已故 2020-12-13 12:35

I know this question is pretty general but I haven\'t found any hints on why this error may show up. What are possible causes of seeing initalizationError in Eclips

相关标签:
25条回答
  • 2020-12-13 12:45

    This problem also occurs if you have a private Rule in you class:

    @Rule
    private TemporaryFolder folderRule;
    

    Make it public.

    0 讨论(0)
  • 2020-12-13 12:47

    In my case, I had the following import in my test case:

    import org.junit.jupiter.api.Test;

    The correct import is:

    import org.junit.Test;

    Don't just import any old Test type from junit, make sure you pick the correct one.

    0 讨论(0)
  • 2020-12-13 12:50

    For me the solution was one of the methods had to be void, I had it as Boolean.

    0 讨论(0)
  • 2020-12-13 12:51

    You've probably got one of two problems:

    1) You're using JUnit 4.11, which doesn't include hamcrest. Add the hamcrest 1.3 library to your classpath.

    2) You've got hamcrest 1.3 on your classpath, but you've got another version of either junit or hamcrest on your classpath.

    For background, junit pre 4.11 included a cut down version of hamcrest 1.1. 4.11 removed these classes.

    0 讨论(0)
  • 2020-12-13 12:51

    For me it was a missing static keyword in one of the JUnit annotated methods, e.g.:

    @AfterClass
    public static void cleanUp() {
        // ...
    }
    
    0 讨论(0)
  • 2020-12-13 12:53

    I've experimented the exact same error. My problem was that the SetUp method I had created was declared as static.

    If using eclipse, one could get a good description by clicking above the error and then checking the Failure trace window, just below... That's how I found the real problem!

    0 讨论(0)
提交回复
热议问题