Reputation: 29
I have seen previous problems on here addressing an issue with running junit tests on VSCode and most solutions suggest adding a JAR to the class path. I have this however when I run my test file it still does not recognize assertEquals. Can someone please explain how I have to set this up? I am trying to run some sample problems for a software course.
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
public class TestGeneratePrimes {
public static void main(String args[]) {
Result result = JUnitCore.runClasses(TestPrimes.class);
for(Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
}
The code above is what I run but it tells me it does not recognize assertEquals which is being called in my TestPrimes class. I'm still very new to this so I apologize if I am not being descriptive enough. I am able to compile other java programs. I just cannot run these JUnit tests.
Upvotes: 2
Views: 928
Reputation: 15
I was facing same issue, got a solution in the docs. Hope this might help you as well https://code.visualstudio.com/docs/java/java-testing
Upvotes: 0
Reputation: 389
I think org.junit.Assert.assertEquals might have been introduced in a version of Junit jar that is not available in your environment. I saw a similar issue with junit-4.10 while the feature I was trying to use was only in junit-4.12.jar and up. It's been a while and I can't be more precise but I suggest you check the junit version in your environment.
Upvotes: 1
Reputation: 11
Your environment may differ/require more configuration, but try importing Assert?
import org.junit.Assert;
Upvotes: 0