简体   繁体   English

如何在Robotium中为Android Apk(仅.apk)测试做所有事情?

[英]How to do everything in Robotium for Android Apk(only .apk) testing?

I would like to know brief skeleton of a Robotium testing project. 我想知道一个Robotium测试项目的简要框架。

For eg: 例如:

I have different classes for each test case and one test suite which has all these test classes. 对于每个测试用例,我都有不同的类,并且一个包含所有这些测试类的测试套件。 But how can we run the project so that it will always call the test suite and not individual classes. 但是我们如何运行该项目,以便它始终调用测试套件而不是单个类。

Do I need to create a Main Class from where I should call all suites? 我需要从哪里调用所有套件来创建一个主类吗? Will that Main class will have legacy main() method or will it have onCreate() method of Android. 该Main类将具有旧版main()方法,还是具有Android的onCreate()方法。 Please guide me. 请指导我。 Also, I am using just apk for Robotium testing. 另外,我仅使用apk进行Robotium测试。

You can follow this guide from Robotium wikipage: 您可以从Robotium Wiki页面遵循此指南:

https://code.google.com/p/robotium/wiki/RobotiumForAPKFiles https://code.google.com/p/robotium/wiki/RobotiumForAPKFiles

You can start from this workspace and adapt to your project following in the guide above: 您可以从该工作空间开始并按照上面的指南适应您的项目:

http://dl.bintray.com/robotium/generic/ExampleTestProject_v5.1.zip http://dl.bintray.com/robotium/generic/ExampleTestProject_v5.1.zip

If you want to run all tests in suit, you had better use JUnit. 如果要运行所有测试,最好使用JUnit。 For example, this is how JUnit join your classes in suit: 例如,这是JUnit如何通过西装加入类的方式:

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

//JUnit Suite Test
@RunWith(Suite.class)
@Suite.SuiteClasses({ 
   Test1.class ,Test2.class
})
public class JunitTestSuite {
}

where Test1, Test2 - your classes with tests Test1,Test2-您的带有测试的类

Below is the simple example of runner for suit: 以下是简单的西装赛跑者示例:

import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

public class TestRunner {
   public static void main(String[] args) {
      Result result = JUnitCore.runClasses(TestJunit.class);
      for (Failure failure : result.getFailures()) {
         System.out.println(failure.toString());
      }
      System.out.println(result.wasSuccessful());
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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