我正在研究依賴於JUnit 4.11
和JMock 2.6.0-RC2
的傳遞依賴項的項目,該依賴項又依賴於JUnit-dep 4.4
。 JUnit-dep
的傳遞依賴關係覆蓋了本地pom中的設置JUnit
。通過重寫,我的意思是當我調用JUnit方法時,它會調用v4.4中的調用,而不是v4.11。爲JMock
和JUnit-dep
添加排除對我解決的依賴關係沒有影響。Maven排除不工作
注:JUnit
和JUnit-dep
有獨立artifactId
S,因此使用一個不會忽略其它。
前一題:不工作
我試圖當我運行測試運行使用JUnit的ExpectedException
規則的考驗JUnit的註解,它看起來好像規則沒有運行。在下面的代碼中,如果規則不存在,那麼異常會直接進行,並且測試失敗。
我最近將項目的Maven依賴項從4.3.1更改爲4.11。我也做了一個乾淨的工作空間。我應該考慮哪些步驟來解決這個問題?來自Maven的trasitive依賴會混淆賽跑者嗎?我怎麼能說我正在用4.11運行?
@Rule
public ExpectedException thrown= ExpectedException.none();
@Test
public void throwsNullPointerException() {
thrown.expect(NullPointerException.class);
throw new NullPointerException();
}
編輯:
我不知道是否有幫助,但加入@RunWith(BlockJUnit4ClassRunner.class)
上我的課的頂部落在我這個:
java.lang.NoSuchFieldError: NULL
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:57)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:57)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.junit.internal.requests.ClassRequest.buildRunner(ClassRequest.java:33)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:28)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:32)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:41)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:31)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
編輯:
在Eclipse中查看通過m2e的依賴關係:當我檢查依賴關係層次結構選項卡我的朋友,我ser 1 已解決依賴關係對於JUnit:4.11和多個(與4.11衝突省略)在左側。另外還有一個已解決的依賴關係對於junit-dep 4.4 from jmock-junit4: 2.6.0-RC2
但是我已經標記了這種依賴關係排除在外(Right-click + Exclude Maven Artifact...
)。此外,由於與我自己致電JMock 2.1.0
的電話衝突,JMock本身被標記爲已忽略。
編輯: Ctrl+Shift+T RunWith
示出了2個版本,4.4 & 4.11儘管排除。
編輯: 加入junit-dep 4.10
「固定」的問題存在依賴關係,終於使ommitting 4.4版本的麻煩。然而,這似乎更多的是一種解決方案。
您是否試圖在IDE或Maven中運行測試?你在使用自定義的JUnit測試運行器嗎? –
在Eclipse中運行。默認跑步者。 – AnthonyW
在您的運行配置中,檢查Eclipse是否正在使用JUnit 3或JUnit4運行器(Test選項卡中的Test runner:字段)。 –