就像link一样,我遇到了同样的问题。我编写了一个代码,它在我的本地机器上运行良好,但无法在Linux机器上运行。代码如下:
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
}
}
,错误如下:
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)
使用
时会发生此错误mvn -U clean test -Dtest "path"
在linux机器上。
那么,问题出在哪里?这真的很奇怪。
PS:虽然我认为我在上面的链接中遇到了同样的问题,但我认为有些不同。首先,答案说问题是在静态块中,但是我使用了try catch,但什么也没有抓到;其次,我认为是因为我启动容器失败了?它已经困扰了我好几天了。