How to assertThat something is null with Hamcrest?

前端 未结 4 718
青春惊慌失措
青春惊慌失措 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:33

    If you want to hamcrest, you can do

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

    In Junit you can do

    import static junit.framework.Assert.assertNull;
    assertNull(object);
    

提交回复
热议问题