How to assertThat something is null with Hamcrest?

前端 未结 4 717
青春惊慌失措
青春惊慌失措 2021-02-01 00:12

How would I assertThat something is null?

for example

 assertThat(attr.getValue(), is(\"\"));

But I get an e

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-01 00:24

    You can use IsNull.nullValue() method:

    import static org.hamcrest.Matchers.is;
    import static org.hamcrest.Matchers.nullValue;
    
    assertThat(attr.getValue(), is(nullValue()));
    

提交回复
热议问题