JUnit like automatic testing application framework. This framework can help developers to build real test applications and create test cases using JUnit like style. It also contains Appium script for automation test and build test matrix.
-
Android Studio 3.0
-
JUnit 4.12
-
Appium
Clone the repo and import to Android Studio. Connect real device and Run AutoTestApp.
-
Build the project
./gradlew app:assembleDebug
-
Start Appium Server
-
Get device list with adb
adb devices
-
Run autotest script
python script/autotest.py -d <device serail numbers seperated by comma>
for more information execute
python script/autotest.py -h
This test framework is very similar to JUnit4. If you familar with JUnit4 unit testing. You can create your own test use that schema.
@Description("My Simple Test")
public class MyTestCase {
@BeforeClass
public static void setupClass() {
// static setup before test class
}
@Before
public void setup() {
// Setup code
}
@Test
public void myTestFunction1() {
assertEquals(4, 2 + 2);
}
@Test
public void myTestFunction2() {
assertNotEquals(4, 2 + 1);
}
@After
public void tearDown() {
// Clean up
}
@AfterClass
public static void tearDownClass() {
// static teardown after test class
}
}TestRunner runner = new TestRunner();//Run a single test
runner.run(MyTestCase.class)
//Run test suite
TestSuite suite = new TestSuite();
suite.add(MyTestCase.class)
runner.run(suite);This test framework reuses [org.junit.Assert] as it's assertion mechanism. To use assertion in TestCase:
import static com.sparktest.autotesteapp.framework.*You can use dagger dependency injection in test cases.
- Provide a Module
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
@Module(
injects = {
TestTest.class,
}
)
public class TestModule {
Context context;
public TestModule(Context context) {
this.context = context;
}
@Provides
@Singleton
public Context provideContext() {
return this.context;
}
}- Use Inject in Test Case
public class TestTest {
@Inject
Context context;
@Test
public void run() {
assertNotNull(context);
}
}Descriptions of TestCase and Test methods. Description will be displayed on TestCaseListView. If no @Description annotation, class name will be used.
Methods to test. Methods annoted with @Test should be public method.
Method annoted with @BeforeClass will be executed before class instantiated. This method should be public static method.
Method annoted with @AfterClass will be executed after all test method are finished or test case failed. This method should be public static method.
Method annoted with @Before will be executed before every @Test method execution.
Method annoted with @After will be executed after every @Test method execution.
Method or Class annoted with @Ignore will be ignored.