florent37 / Androidunittest
Licence: apache-2.0
Save time & clear your unit tests on Android !
Stars: ✭ 205
Programming Languages
java
68154 projects - #9 most used programming language
Projects that are alternatives of or similar to Androidunittest
Test Smells
Test Smells for Android developers
Stars: ✭ 120 (-41.46%)
Mutual labels: unit-testing, junit, robolectric
EasyUtAndroid
Android unit testing example 全面的android应用单元测试方法及案例
Stars: ✭ 21 (-89.76%)
Mutual labels: unit-testing, junit, robolectric
Sample Code Movies
This repository contains sample code. Its purpose being, to quickly demonstrate Android and software development in general, clean code, best practices, testing and all those other must know goodies.
Stars: ✭ 81 (-60.49%)
Mutual labels: unit-testing, robolectric
Atoum
The modern, simple and intuitive PHP unit testing framework.
Stars: ✭ 1,382 (+574.15%)
Mutual labels: test, unit-testing
Kotlin Espresso Sample
MVP Android project that uses Espresso instrumentation tests and Robolectric. All written in Kotlin.
Stars: ✭ 104 (-49.27%)
Mutual labels: junit, robolectric
Django Jenkins
Plug and play continuous integration with django and jenkins
Stars: ✭ 933 (+355.12%)
Mutual labels: test, unit-testing
Junitperf
⛵️Junit performance rely on junit5 and jdk8+.(java 性能测试框架)
Stars: ✭ 86 (-58.05%)
Mutual labels: test, junit
Snap Shot
Jest-like snapshot feature for the rest of us, works magically by finding the right caller function
Stars: ✭ 170 (-17.07%)
Mutual labels: test, unit-testing
Vscode Java Test
Run and debug Java test cases in Visual Studio Code.
Stars: ✭ 177 (-13.66%)
Mutual labels: test, junit
Robolectric
Android Unit Testing Framework
Stars: ✭ 5,372 (+2520.49%)
Mutual labels: unit-testing, robolectric
System Rules
A collection of JUnit rules for testing code which uses java.lang.System.
Stars: ✭ 492 (+140%)
Mutual labels: unit-testing, junit
Junit Extensions
JUnit5 extensions library including JUnit5 equivalents of some of the common JUnit4 rules: ExpectedException, TemporaryFolder etc
Stars: ✭ 39 (-80.98%)
Mutual labels: unit-testing, junit
Video Recorder Java
This library allows easily record video of your UI tests by just putting couple annotations.
Stars: ✭ 179 (-12.68%)
Mutual labels: test, junit
Clean Mvvm Archcomponents
👽 Android app consuming Star Wars API.Built with clean architecture ,MVVM pattern, Koin , Coroutines + Flows ,Architecture Components, Data Binding , Firebase , Unit/UI Tests ,Motion Layout
Stars: ✭ 285 (+39.02%)
Mutual labels: junit, robolectric
Android Gif Example
Gif RecyclerView in MVP using Dagger 2 + Retrofit 2 + Moshi + RxJava 2 + Glide 4 with JUnit and Espresso tests written in Kotlin + Kotlin DSL!
Stars: ✭ 334 (+62.93%)
Mutual labels: junit, robolectric
Spectrum
A BDD-style test runner for Java 8. Inspired by Jasmine, RSpec, and Cucumber.
Stars: ✭ 142 (-30.73%)
Mutual labels: unit-testing, junit
Android Unit Test
Save time & clear your unit tests on Android !
Use annotations to inject Context, Activities, Fragments and Views into your tests
Usage
@RunWith(CustomTestRunner.class)
public class MainActivityTest {
@Rule public AndroidUnitTest androidUnitTest = AndroidUnitTest.rule();
@RContect Context context; //inject the app context
@RActivity MainActivity activity; //generates the tested activity
@Mock User user; //mock an user
@Test
public void testDisplayUser() throws Exception {
// Given
given(user.getName()).willReturn("florent");
// When
activity.display(user);
// Then
assertThat(activity.textView.getText()).isEqualTo("florent");
}
}
TestRunner
Simplify Robolectric Integration
public class CustomTestRunner extends AndroidUnitTestRunner {
public CustomTestRunner(Class<?> testClass) throws InitializationError {
super(testClass, BuildConfig.FLAVOR, BuildConfig.BUILD_TYPE, BuildConfig.APPLICATION_ID, TestMyApplication.class);
}
}
Activity
Set initial activity state (by default activity is created())
@RunWith(CustomTestRunner.class)
public class MyTest {
@Rule public AndroidUnitTest androidUnitTest = AndroidUnitTest.rule();
@RActivity(state = CREATED / STARTED / RESUMED / PAUSED / STOPPED / DESTROYED)
MainActivity activity;
@Test
public void testMyFunction(){
androidUnitTest.activity().resume();
}
}
Note that the injected activity is a spy !
verify(activity, times(2)).someMethod(anyInt());
Context
Retrieve Context easily
@RunWith(CustomTestRunner.class)
public class MyTest {
@Rule public AndroidUnitTest androidUnitTest = AndroidUnitTest.rule();
@RContext Context context;
}
Note that the injected context is a spy !
verify(context, times(2)).someMethod(anyInt());
View
@RunWith(CustomTestRunner.class)
public class MyTest {
@Rule public AndroidUnitTest androidUnitTest = AndroidUnitTest.rule();
@RView CustomView customView;
@Test
public void testDisplayUser() throws Exception {
// Given
given(user.getName()).willReturn("florent");
// When
mainView.display(user);
// Then
verify(customView).displayText("florent");
}
}
Note that the injected view is a spy !
Fragment
@RunWith(CustomTestRunner.class)
public class MyTest {
@Rule public AndroidUnitTest androidUnitTest = AndroidUnitTest.rule();
@RFragment MyFragment myFragment;
@Mock User user;
@Test
public void testDisplayUser() throws Exception {
// Given
given(user.getName()).willReturn("florent");
// When
myFragment.display(user);
// Then
verify(myFragment).displayText("florent");
}
}
@RunWith(CustomTestRunner.class)
public class MyTest {
@Rule public AndroidUnitTest androidUnitTest = AndroidUnitTest.rule();
@RFragment(
attached = true / false,
tag = "fragmentTag"
)
MyFragment myFragment;
@Test
public void testMyFunction() throws Exception {
androidUnitTest.fragment().addToActivity(myFragment)
}
}
Note that the injected fragment is a spy !
Download
testCompile 'com.github.florent37:androidunittest:(last version)'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.robolectric:robolectric:3.0'
Credits
Author: Florent Champigny
License
Copyright 2016 florent37, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].