I'm trying to make Junit tests. I want to start them by asking for a method in the CMS system. Because I'm testing plugins. The problem is that I get this exception and I don't know why. Naah I find that the problem could be that I'm using JUnit 4.8.2, but when I'm running the test in Eclipse everything worked fine. So I can't find the solution. Here is the error:
org.apache.velocity.exception.MethodInvocationException: Invocation of method
'getTest' in class nl.company.cms.three.viewtool.LoginViewTool threw exception
java.lang.NoClassDefFoundError: org/junit/internal/AssumptionViolatedException at
working/2a90929a-3fbf-43e9-9961-4a40279ec907_5c6e0bff-cfeb-44c6-86e2-
a0ba40e7b66c.field[line 1, column 15]
Here is the code of my class and test class: Class that calls to start the Test:
public String getTest(){
Result r = org.junit.runner.JUnitCore.runClasses(MyTestClass.class);
if(r.getRunCount() > 0){
String s = "Failcount = " + r.getFailureCount() + " // " +
r.getRunCount() + " in " + r.getRunTime() + " ms";
System.out.println(r.getFailures().get(0).getTrace());
System.out.println("Runcount: "+r.getRunCount());
System.out.println("Runtime: "+r.getRunTime());
System.out.println("Ignore count: "+r.getIgnoreCount());
System.out.println("Failure count: "+ r.getFailureCount());
return s;
}
else{
return "Something ging kei verkeerd jonge!";
}
}
Test class:
public class MyTestClass {
@Test
public void testMultiply() {
CustomLoginViewTool tester = new CustomLoginViewTool();
assertEquals("Result", 40, tester.multiply(10, 5));
}
@Test
public void testMultiply1() {
CustomLoginViewTool tester = new CustomLoginViewTool();
assertEquals("Result", 50, tester.multiply(10, 5));
}
@Test
public void testMultiply2() {
CustomLoginViewTool tester = new CustomLoginViewTool();
assertEquals("Result", "ASDF", tester.multiply(10, 5));
}
@Test
public void testMultiply3() {
CustomLoginViewTool tester = new CustomLoginViewTool();
assertEquals("Result", 50, tester.multiply(10, 5));
}
@Test
public void testMultiply4() {
CustomLoginViewTool tester = new CustomLoginViewTool();
assertEquals("Result", 47, tester.multiply(10, 5));
}
@Test
public void testMultiply5() {
CustomLoginViewTool tester = new CustomLoginViewTool();
assertEquals("Result", 50, tester.multiply(10, 5));
}
}
Assumptions are exceptions that JUnit will catch but which won't fail the test. These are for "this test only makes sense if" kind of questions. There is no point to fail Windows-path tests on a Linux system, for example - they can't succeed and failing them will give you an error that you can't fix without disabling the tests.
What I find odd is Velocity and JUnit in a single error message. Why is Velocity running JUnit?
The error means that the classpath isn't set up correctly. So you need to look into the classloader which is used to load the class which contains the method getTest()