문제

How would I assertThat something is null?

for example

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

But I get an error saying that I cannot have null in is(null).

도움이 되었습니까?

해결책

You can use IsNull.nullValue() method:

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;

assertThat(attr.getValue(), is(nullValue()));

다른 팁

why not use assertNull(object) / assertNotNull(object) ?

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);

Use the following (from Hamcrest):

assertThat(attr.getValue(), is(nullValue()));

In Kotlin is is reserved so use:

assertThat(attr.getValue(), `is`(nullValue()));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top