2011-03-13 6 views
23

PowerMock 테스트 러너를 사용하여 junit 테스트 케이스를 실행 중입니다. 내가 그것을 실행하기 위해 다음 명령 줄을 사용하고 있습니다 :Powermock을 사용할 때 NoClassDefFoundError

java -cp .:junit-4.9b2.jar:easymock-3.0.jar:powermock-easymock-1.4.8-full.jar org.junit.runner.JUnitCore SampleTest 

그래서이 오류 수신하고 일 :

initializationError(SampleTest) 
java.lang.NoClassDefFoundError: org/junit/internal/runners/TestClassRunner 
... 

내가 그것을 어떻게 해결할 수 있습니까?

답변

0

나는이 문제를 해결했다. 이전 버전 인 junit-4.0.jar를 사용했습니다. 하지만 여전히 powermock-easymock-junit-1.4.8.zip 패키지 (특히 junit-4.8.2.jar)에서 TestClassRunner 클래스가 누락 된 이유를 아직 이해하지 못하고 있습니까? junit-4.8.2.jar에는 TestClassRunner 클래스도 없습니다. 나는 @RunWith(PowerMockRunner.class) 속성을 추가 할 때

내가 지금이 일을 해결
+0

를 참조하십시오. 내 대답을 참조하십시오 – RonK

63

는, eclipse 자동으로 가져옵니다 :

import org.powermock.modules.junit4.legacy.PowerMockRunner; 

내가 그것을 변화 할 필요가 모든 수 :

import org.powermock.modules.junit4.PowerMockRunner; 

그리고 지금 JUnit 4.8.2으로 잘 작동합니다.

두 번째 주자는 JUnit의 이전 버전, 특히 4.3 이상으로 실행하는 경우입니다. 단지 해결 방법 -

+0

답변 주셔서 감사합니다. – jatanp

+0

정말 고마워요! – NiranjanBhat

+1

정말 고마워요. – shafeeq

5

이 올바른 해결책이 아니다 here

You're probably using the wrong PowerMockRunner. There's one runner made for JUnit 4.4 and above and a second runner made for JUnit 4.0-4.3 (although the latter also works for some older minor versions of JUnit 4.4).
Try switching from the org.powermock.modules.junit4.PowerMockRunner to org.powermock.modules.junit4.legacy.PowerMockRunner or vice versa. Look at the getting started guide to see how to configure this in maven.

관련 문제