this is my code of file AllTests:
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
ElementTests.class
})
public class AllTest {}
ElementTests.java
import org.junit.Test;
import pl.polsl.lab1.Model.*;
import static org.junit.Assert.*;
import org.junit.Test;
public class ElementTests {
@Test
public void properSymbolPlayerTest()
{
//given
ElementOfBoard element = new ElementOfBoard();
ElementOfBoard element2 = new ElementOfBoard();
//when
element.setSymbol(1);
element.setSymbol(2);
//then
assertEquals('O', element);
assertEquals('X', element2);
}
}
My error
Please, how to solve it? I am using junit 4.11. I really have no idea what initialization error could be. Can you help me please?
My Stack trace:
org/hamcrest/SelfDescribing
java.lang.NoClassDefFoundError
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.getConstructor(Class.java:1825)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Show activity on this post. Right click your project in Package Explorer > click Properties go to Java Build Path > Libraries tab click on 'Add Library' button select JUnit click Next.
An ExceptionInInitializerError is thrown to indicate that an exception occurred during evaluation of a static initializer or the initializer for a static variable. As of release 1.4, this exception has been retrofitted to conform to the general purpose exception-chaining mechanism.
That should solve this problem.
In my case the issue was I had accidentally commented out @Test before the method I was trying to test. So it was throwing the initialization error and method not available.
This can also happen if we have @Ignore on the class level.
Please check @Test annotaion
is added and imported from the right import path import org.junit.Test;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With