3 回答

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超10個(gè)贊
當(dāng)您已經(jīng)在類路徑上使用了mockito-all時(shí),也會(huì)出現(xiàn)此問(wèn)題。
如果可能的話,只需包括模仿主體。
用于混合junit,mockito和hamcrest的Maven配置:
<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>

TA貢獻(xiàn)1779條經(jīng)驗(yàn) 獲得超6個(gè)贊
問(wèn)題是使用了錯(cuò)誤的類而hamcrest.Matcher不是hamcrest.MatcherAssert類。這是從junit-4.8依賴項(xiàng)中提取的,這是我的一個(gè)依賴項(xiàng)。
要查看在測(cè)試時(shí)從哪個(gè)來(lái)源包含了哪些依賴項(xiàng)(和版本),請(qǐng)運(yùn)行:
mvn dependency:tree -Dscope=test
添加回答
舉報(bào)