कैसे कि मैंने assertThatकुछ है null?
उदाहरण के लिए
assertThat(attr.getValue(), is(""));
लेकिन मैं कह रही है कि मैं नहीं हो सकता है कोई त्रुटि मिलती है nullमें is(null)।
कैसे कि मैंने assertThatकुछ है null?
उदाहरण के लिए
assertThat(attr.getValue(), is(""));
लेकिन मैं कह रही है कि मैं नहीं हो सकता है कोई त्रुटि मिलती है nullमें is(null)।
जवाबों:
आप IsNull.nullValue()विधि का उपयोग कर सकते हैं :
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
IsNullयह उस कक्षा में एक स्थिर विधि है। बस करो static import, या उपयोग करो IsNull.nullValue()।
import static org.hamcrest.core.IsNull.nullValue;अपनी कक्षा में जोड़ें ।
import static org.hamcrest.CoreMatchers.nullValue।
क्यों नहीं उपयोग assertNull(object)/ assertNotNull(object)?
आप चाहें hamcrestतो कर सकते हैं
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
में Junitआप कर सकते हैं
import static junit.framework.Assert.assertNull;
assertNull(object);