简体   繁体   中英

Getting null pointer exception error after change assert expression

I'm testing the result of my AsyncTask. Since I'm using a local Google Cloud Endpoint, the test runs to completion after stopappengine, rebuild project and sartappengine again. But, when I change the assert expression it gives me this strange NullPointerException below.

Observation: When I rebuild the project the test runs to completion with either assert expressions ("==" or "!="). No matter which one is the assert expression, if I change it, it gives me the same e NullPointerException. Then the test NEVER runs normally again, giving me always the same error.

JUnitTest:

@RunWith(AndroidJUnit4.class)
public class EndPointAsyncTaskTest {

    @Test
    public void testDoInBackground() throws Exception {

        MainActivityFragment fragment = new MainActivityFragment();

        EndpointsAsyncTask endpointsAsyncTask = new EndpointsAsyncTask();
        fragment.testFlag = true;
        endpointsAsyncTask.execute(fragment);

        Thread.sleep(5000);
        assertTrue("Error: Fetched Joke = " + fragment.jokeContent,
                fragment.jokeContent != "");

    }
}

NullPointerException error:

Test running failed: There was 1 failure:
1) Fatal exception when running tests
java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference
at java.util.regex.Matcher.reset(Matcher.java:995)
at java.util.regex.Matcher.<init>(Matcher.java:174)
at java.util.regex.Pattern.matcher(Pattern.java:1006)
at android.support.test.internal.runner.TestRequestBuilder$MethodFilter.stripParameterizedSuffix(TestRequestBuilder.java:524)
at android.support.test.internal.runner.TestRequestBuilder$MethodFilter.evaluateTest(TestRequestBuilder.java:510)
at android.support.test.internal.runner.TestRequestBuilder$ParentFilter.shouldRun(TestRequestBuilder.java:145)
at android.support.test.internal.runner.TestRequestBuilder$ClassAndMethodFilter.evaluateTest(TestRequestBuilder.java:452)
at android.support.test.internal.runner.TestRequestBuilder$ParentFilter.shouldRun(TestRequestBuilder.java:145)
at org.junit.runner.manipulation.Filter$3.shouldRun(Filter.java:112)
at org.junit.runners.ParentRunner.shouldRun(ParentRunner.java:434)
at org.junit.runners.ParentRunner.filter(ParentRunner.java:382)
at org.junit.runner.manipulation.Filter.apply(Filter.java:97)
at android.support.test.internal.runner.TestRequestBuilder$LenientFilterRequest.getRunner(TestRequestBuilder.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932)

FAILURES!!!
Tests run: 0,  Failures: 1
Empty test suite.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM