Android

assert obj != null VS Assert.ass

2019-02-27  本文已影响6人  JaedenKil
@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.

上一篇 下一篇

猜你喜欢

热点阅读