簡體   English   中英

Hamcrest斷言那個含糊不清?

[英]Hamcrest assertThat ambiguous?

我從大學獲得了一些樣本代碼,導入了項目並嘗試運行測試:方法assertThat(Integer,Matcher)對於MyClass類型是不明確的

每個斷言都標記為紅色,並顯示相同的錯誤消息,因此我嘗試編寫描述問題的最簡單的測試:

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

@Test
public void whenAssertThatThenItIsAmbiguous() {
    List<String> list = Arrays.asList("A", "B", "C");
    assertThat(list.size(), is(3));
}

滾動斷言后,我收到以下消息:

The method assertThat(Integer, Matcher<Integer>) is ambiguous for the type MyClass

我搜索了谷歌和stackoverflow但找不到任何有同樣問題的人...請幫忙。

EDIT1:

解:

import static org.junit.Assert。*; //刪除這一行

org.junit.Assertorg.hamcrest.MatcherAssert聲明assertThat(T, Matcher<T>) 選擇靜態導入一個或另一個,但不是兩個,你應該沒問題。

這有兩個一般原因,不合格的靜態導入( import static blah.* ),或路徑上的多個版本的hamcrest。

您可以通過使用long-form is(equalTo(3)) (有點懷疑),剔除靜態導入等來繞過它。

您使用它的哪個框架也很重要。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM