2011-04-27 17 views
16

我最近試圖在一個測試中斷言不平等。但我無法在hamcrest找到合適的匹配器。 我理想想要做的是類似的。在hamcrest中使用不操作

assertThat(2 , isNot(3)); 

有沒有辦法做到這一點?

回答

22

就快:

assertThat(2 , is(not(3))); 
+4

,除非'是()'是唯一匹配目前,這是不必要的語法糖。 'assertThat(2,not(3));'也適用於這裏。 – 2011-04-28 22:23:06

8

確保您導入:

import static org.hamcrest.CoreMatchers.not;