Just like the link, I have met a same question. I write a code, which runs well on my local machine but could not work on a linux machine. The code is as follows:
public class BaseCase{
public static ServiceFactory factory = ServiceFactory.getInstance();
static{
//the factory is a container, and code here is to insert some processes into it,and there is a try catch
}
}
and the error is as follows:
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec <<< FAILURE! - in xxx.足迹找相似.P1_足迹着相似_回归_Tes
xxx.足迹找相似.P1_足迹着相似_回归_Test Time elapsed: 0 sec <<< ERROR!
java.lang.NoClassDefFoundError: Could not initialize class com.taobao.testcase.BaseCase
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
This error happens when I used
mvn -U clean test -Dtest "path"
on the linux machine.
So, where is the problem? That is really strange.
PS:though I think I have met the same question in the link above,but I think there is something different. Firstly, the answer said that the problem is in the static block, but I used a try catch,but catch nothing; secondly, I think would it because I start the container failed? It has already confused me for days.