Could not find class in Junit-4.11

前端 未结 2 1718
我寻月下人不归
我寻月下人不归 2021-01-06 08:40

I configured Junit-4.11 on my Mac, compile with javac has no error, but when I run with java, I got Could not find class: HelloWorldTest

2条回答
  •  感情败类
    2021-01-06 09:08

    Update: The original poster's solution is buried in a comment below. It has to do with not having the junit jar files in /Library/Java/Extensions, and not having a CLASSPATH:

    I deleted CLASSPATH in my .zshrc file, and I also deleted junit-4.11.jar in /Library/Java/Extensions and /Library/Java/Home/lib/ext, and then JUnit-4.11 worked.


    In a temp dir (java files from your question):

    HelloWorld.java
    HelloWorldTest.java
    junit-4.11.jar
    hamcrest-core-1.3.jar
    

    Then:

    • javac -cp junit-4.11.jar *.java
    • java -cp junit-4.11.jar:hamcrest-core-1.3.jar:. org.junit.runner.JUnitCore HelloWorldTest

    Output:

    HelloWorldTest
    JUnit version 4.11
    @BeforeClass - oneTimeSetUp
    .@Before - setUp
    @Test - testOutput
    @After - tearDown
    @AfterClass - oneTimeTearDown
    
    Time: 0,004
    
    OK (1 test)
    

    I would advise retrying from scratch

提交回复
热议问题