Android Instrumentation Tests Stuck “Running Tests” Forever Android Studio

别说谁变了你拦得住时间么 提交于 2019-12-23 17:24:42

问题


I use Android Espresso Tests with latest Android Studio 2.1.2 and Tests are running ok but it does not seems like the standalone test app returns back the results to reflect back to Android Studio and it shows Running Tests Forever


回答1:


I realize this is an old question, but I just ran into this and didn't see any other search results that had the same problem.

In my case, this was caused by the code under test having a stack overflow exception, which it seems that the test runner failed to handle. I was only able to figure it out by looking at the "Android Monitor" and looking in the logcat.

So if you get to the point where AS just sits at "running test" forever, you might want to look in logcat for an exception that the test runner couldn't handle.




回答2:


You have to try removing testCoverageEnabled option from build.gradle file if it's there. possible duplicate Gradle build tool long for android Tests




回答3:


In case this helps anyone. In my case, I was setting the idle state wrongly(false instead of true) after doing a background task, so espresso was stuck thinking that was idle.




回答4:


You can add an exit test class like this and include this in your Test Suite or Executor in the last

import android.os.Looper;

import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;

import org.junit.FixMethodOrder;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;

import java.io.IOException;

import static androidx.test.InstrumentationRegistry.getInstrumentation;

@RunWith(AndroidJUnit4.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ExitTests {

    @Rule
    public ActivityTestRule<MainActivity> myActivityTestRule =
            new ActivityTestRule<>(MainActivity.class, false, true);

    public void init(){
        getInstrumentation().waitForIdleSync();
        if(Looper.myLooper() == null)
            Looper.prepare();
    }


    @Test
    public void Exit() throws InterruptedException, IOException {
        Runtime.getRuntime().exec(new String[] {"am", "force-stop", "com.package.name"});
    }
}

Here is the Test Suite

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({ABC.class, ExitTests.class})
public class TestExecutionOrder {

}


来源:https://stackoverflow.com/questions/37839495/android-instrumentation-tests-stuck-running-tests-forever-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!