2012-04-25 21 views
0

我在我的項目中找到了屬於Junit的包(在org.junit, org.junit.experimental.results, org.junit.internal, org.junit.internal.matchers, org.junit.matchers, org.junit.rules)的編譯錯誤。Java /使用Junit 4給出編譯錯誤

所有這些類都在我項目中的junit包中,意思是:Security/src/org.junit, Security/src/org.junit.experimental.results,其中Security是我的項目名稱。我的班,我寫的是在我定義其他包:Security/src/myPackage/myClass

在所有這些類別,它提供了complation錯誤的進口線路,例如:

import org.hamcrest.Description cannot be resolved 
import org.hamcrest.Matcher cannot be resolved; 
import static org.junit.matchers.JUnitMatchers.containsString cannot be resolved; 

的檢查會確定(在顯示綠色/紅色條,並給出正確的結果),但是這個問題在所有項目中給我一個錯誤。

回答

4

您的JUnit版本需要Hamcrest。您應該將其包含在構建路徑中或使用較舊的JUnit版本。

有釋放4.10不同的JUnit包:

  • 的JUnit 4.10.jar:包括Hamcrest,你應該使用這個。
  • junit-dep-4.10.jar:不包含Hamcrest,如果您的buildpath中已經有hamcrest jar,請使用它。
+0

在第一個中,我只導入了junit-4.10.jar。但它寫道:'導入org.junit無法解析','無法解析導入junit'。爲此,我安裝了junit-dep-4.10.jar,它給了我這些問題。 – 2012-04-25 14:41:46