Android Espresso黑盒测试

时间:2015-07-21 03:06:45

标签: android android-testing android-espresso

是否有人尝试使用black-box testing {/ 1}进行Android Espresso

有人能为我提供一些简单的例子吗?

之前我曾尝试过一些例子,但每次都失败了!

例子,我试过这个:

public class ApplicationTest extends ActivityInstrumentationTestCase2
{

private static final String ACTIVITY_CLASSNAME = "com.example.kai_yu.blackboxtest";

private static Class launchActivityClass;
static
{
    try
    {
        launchActivityClass = Class.forName(ACTIVITY_CLASSNAME);
    }
    catch (ClassNotFoundException e)
    {
        throw new RuntimeException(e);
    }
}

public ApplicationTest()
{
    super(launchActivityClass);
}

@Test
public void testClick()
{

}

}

但是Android Studio说:

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.kai_yu.blackboxtest"

com.example.kai_yu.blackboxtest is applicationId which is another installed application on my phone

谢谢!

3 个答案:

答案 0 :(得分:1)

Espresso只能作为仪器测试的一部分运行。 仪器测试只能对被测试的应用程序(即仪器的目标)起作用。

UIAutomator可能更适合您的用例。

https://developer.android.com/tools/testing-support-library/index.html#UIAutomator

答案 1 :(得分:0)

Espresso文档中,您会找到以下行:

 While it can be used for black-box testing, Espresso's full power is unlocked by those who are familiar with the code base under test."

因此,gray-box testing调用Espresso测试。

如果您不熟悉Java或Android编程,或者只想以最清晰的方式编写black-box testing,请尝试学习而不是Espresso此框架

  

Calabash-iOSCalabash-Android是底层的低级库,它们使Cucumber工具能够在Android上运行自动功能测试......

网站:https://calaba.sh/

GitHub:https://github.com/calabash

在这里,您将了解如何以及为何开始使用此框架: http://blog.teddyhyde.com/2013/11/04/a-better-way-to-test-android-applications-using-calabash/

答案 2 :(得分:0)

@RunWith(AndroidJUnit4.class)
@LargeTest
public class EspressoTest1 extends ActivityInstrumentationTestCase2<MainActivity>{

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

        @Before 
         public void setUp() throws Exception {
            super.setUp();
            injectInstrumentation(InstrumentationRegistry.getInstrumentation());
        }

        @Test 
        public void test1ChatId() {
            getActivity();
            onView(withId(R.id.anuja)).check(matches(isDisplayed()));
        }

        @After        public void tearDown() throws Exception {
            super.tearDown();
        }
}

有两种方法可以编写Espresso Test case,如上图所示 这些例子来自这个博客 http://qaautomated.blogspot.in/p/blog-page.html

在哪里可以找到详细的热点来详细运行espresso测试用例。