JUnit: 4.8.1 "Could not find class"

Well, I, like others, are new to jUnit and have a hard time trying to get it to work. I searched the forum, but the answers are provided; I just do not understand. If anyone there could lend me a hand, I would really appreciate it.

Let me outline the basics: OS: Mac OS X.6

export JUNIT_HOME="/Developer/junit/junit4.8.1" export CVSROOT="/opt/cvsroot" export PATH="/usr/local/bin:/usr/local/sbin:/usr/localmysql/bin:/opt/PalmSDK/Current/bin/:/usr/local/mysql/bin:$PATH:$JUNIT_HOME:$CVSROOT" export CLASSPATH="$CLASSPATH:$JUNIT_HOME/junit-4.8.1.jar:$JUNIT_HOME" 

I can compile a test class from a java file, however, when I try to run a test

 java org.junit.runner.JUnitCore MyTest.class 

I get the following:

 JUnit version 4.8.1 Could not find class: MyTest.class Time: 0.001 OK (0 tests) 

Now I was in the directory with MyTest.class , which is located somewhere in my file system, I tried to move the source folder to the junit folder and the junit/junit4.8.1 and the same result. I can't even run the tests that came with junit.

+4
source share
3 answers

Is MyTest in the package by default? If not, then you need to give the full name corresponding to the package. In other words, if MyClass has an operator

 package com.myself; 

and lives in

 /myproject/src/com/myself/MyClass.java 

and you compiled into

 /myproject/classes 

then /myproject/classes should be on your CLASSPATH , and you should

 java org.junit.runner.JUnitCore com.myself.MyTest 

Think about it, now I see that you are adding .class to the class name, so even if it's in the default package, you should just say

 java org.junit.runner.JUnitCore MyTest 
+7
source

Remove .class from MyTest.class, i.e. java org.junit.runner.JUnitCore MyTest

+2
source

We have no problem finding JUnit - it's finding. It cannot find MyClass, so the directory of this class (given its absence in packaging) should be on the way to the classes.

0
source

Source: https://habr.com/ru/post/1304489/


All Articles