美文网首页Android
assert obj != null VS Assert.ass

assert obj != null VS Assert.ass

作者: JaedenKil | 来源:发表于2019-02-27 17:31 被阅读6次
@RunWith(AndroidJUnit4.class)
public class AssertDemo {

    String TAG = "TAG";

    @Test
    public void mainTest() {
        UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
        UiObject2 obj = mDevice.findObject(By.text("Some Fake String."));

        if (obj == null) {
            Log.d(TAG, "obj is null.");
        } else {
            Log.d(TAG, "obj is not null.");
        }

        assert obj != null;

        Assert.assertNotNull(obj); // Line 33

    }
}
Log:
TAG: obj is null.

junit.framework.AssertionFailedError
...
at xxx.mainTest(AssertDemo.java:33)

So, in junit test, use Assert.assertNotNull(obj) rather than assert obj != null.

相关文章

网友评论

    本文标题:assert obj != null VS Assert.ass

    本文链接:https://www.haomeiwen.com/subject/fxnfuqtx.html