Эспрессо тестирует андроид

Запускаю тесты в Android Studio, запускаю задачу - "тест". Мой тест не удался, мой подробный отчет html:

   junit.framework.AssertionFailedError: Class Test has no public constructor TestCase(String name) or TestCase()
        at junit.framework.Assert.fail(Assert.java:57)
        at junit.framework.TestCase.fail(TestCase.java:227)
        at junit.framework.TestSuite$1.runTest(TestSuite.java:100)
        at junit.framework.TestCase.runBare(TestCase.java:141)
        at junit.framework.TestResult$1.protect(TestResult.java:122)
        at junit.framework.TestResult.runProtected(TestResult.java:142)
        at junit.framework.TestResult.run(TestResult.java:125)
        at junit.framework.TestCase.run(TestCase.java:129)
        at junit.framework.TestSuite.runTest(TestSuite.java:255)
        at junit.framework.TestSuite.run(TestSuite.java:250)
        at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)

Мой исходный файл:

    @LargeTest
public class Test extends ActivityInstrumentationTestCase2<MainActivity>{

    public Test(Class <MainActivity> activityClass) {
        super(activityClass);
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();
        getActivity();
    }

    public void testCheck(){
        onView(withId(R.id.text))
                .check(matches(withText("Hello world!")));
    }
}

person harmashalex    schedule 17.06.2014    source источник


Ответы (2)


Проблема именно в том, о чем говорится в сообщении об ошибке: вы не предоставили конструктор без параметров.

Добавьте этот конструктор в свой тестовый класс:

public Test() {
    super(MainActivity.class);
}
person haffax    schedule 17.06.2014
comment
Я пробовал, но тест тоже провалился. Отчет: junit.framework.AssertionFailedError: Исключение в конструкторе: testCheck (java.lang.RuntimeException: Stub! at android.test.InstrumentationTestCase.‹init›(InstrumentationTestCase.java:5) - person harmashalex; 17.06.2014
comment
Похоже, вы используете средство запуска тестов JUnit по умолчанию вместо GoogleInstrumentationTestRunner - person ivagarz; 17.06.2014
comment
Нет, я использую GoogleInstrumentationTestRunner.Code из моего файла gradle: testInstrumentationRunner com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner - person harmashalex; 18.06.2014

Прототип тестового занятия с эспрессо должен быть:

public class MainTest extends
        ActivityInstrumentationTestCase2<MainActivity>{

    public MainTest() {
        super(MainActivity.class);
    }

    @Override
    public void setUp(){
        getActivity();
    }

    @Override
    public void tearDown(){
    }

    public void test1(){

    }

    public void test2(){

    }
}
person xurxodev    schedule 05.12.2014