Skip to content

Instantly share code, notes, and snippets.

View rafaeltoledo's full-sized avatar

Rafael Toledo rafaeltoledo

View GitHub Profile
apply plugin: 'jacoco'
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
reports {
xml.enabled = true
html.enabled = true
}
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
apply plugin: 'jacoco'
task jacocoTestReport(type: JacocoReport, dependsOn: 'testDebugUnitTest') {
reports {
xml.enabled = true
html.enabled = true
}
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
apply plugin: 'jacoco'
task jacocoTestReport(type: JacocoReport, dependsOn: 'testDebugUnitTest') {
reports {
xml.enabled = true
html.enabled = true
}
jacocoClasspath = configurations['androidJacocoAnt']
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 22)
public class MainActivityTest {
@Test
public void shouldHideButtonAfterClick() {
MainActivity activity = Robolectric.setupActivity(MainActivity.class);
Button button = (Button) activity.findViewById(R.id.hide);
button.performClick();
android {
...
buildTypes {
debug {
testCoverageEnabled true
}
...
}
}
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MainActivityTest {
@Rule
public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class);
@Test
public void shouldUpdateTextAfterButtonClick() {
onView(withId(R.id.button)).perform(click());
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private TextView text;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button).setOnClickListener(this);
android {
lintConfig {
lintConfig file("${project.rootDir}/config/lint.xml")
}
}
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="InvalidPackage" severity="ignore" />
</lint>