Add Robolectric dependency; implement a basic test

pull/231/merge
Alinson S. Xavier 8 years ago
parent 9f2f8f7117
commit cd3944b90f

@ -45,6 +45,9 @@ android {
outputs.upToDateWhen { false }
showStandardStreams = true
}
jacoco {
includeNoLocationClasses = true
}
}
}
}
@ -60,6 +63,7 @@ dependencies {
androidTestCompile "com.google.dexmaker:dexmaker:1.2"
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'com.google.guava:guava:20.0'
apt 'com.google.dagger:dagger-compiler:2.2'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
@ -79,6 +83,7 @@ dependencies {
compile 'org.jetbrains:annotations-java5:15.0'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.google.code.findbugs:jsr305:2.0.1'
compile 'com.google.guava:guava:20.0'
provided 'javax.annotation:jsr250-api:1.0'
@ -87,23 +92,13 @@ dependencies {
}
testApt 'com.google.dagger:dagger-compiler:2.2'
testApt 'com.google.guava:guava:20.0'
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.json:json:20160810'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2.1') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
exclude group: 'com.android.support'
}
testCompile 'org.robolectric:robolectric:3.3.2'
}
retrolambda {
@ -111,7 +106,7 @@ retrolambda {
}
jacoco {
toolVersion = "0.7.5.201505241946"
toolVersion = "0.7.6.201602180812"
}
task coverageReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) {
@ -133,6 +128,7 @@ task coverageReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) {
'**/*$ViewBinder*',
'**/*MembersInjector*',
'**/*_Provide*',
'**/*Module_*',
'**/com/android/**/*',
'android/**/*',
'**/*Dagger*',

@ -38,7 +38,7 @@ import java.util.concurrent.*;
import static junit.framework.Assert.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.CoreMatchers.*;
public class BaseAndroidTest
{

@ -31,7 +31,7 @@ import org.junit.runner.*;
import java.io.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.CoreMatchers.*;
@RunWith(AndroidJUnit4.class)
@MediumTest

@ -30,7 +30,7 @@ import org.junit.runner.*;
import java.io.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.CoreMatchers.*;
@RunWith(AndroidJUnit4.class)
@MediumTest

@ -28,7 +28,7 @@ import org.junit.*;
import org.junit.runner.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.CoreMatchers.*;
import static org.mockito.Mockito.*;
@RunWith(AndroidJUnit4.class)

@ -29,7 +29,7 @@ import org.junit.*;
import org.junit.runner.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.CoreMatchers.*;
import static org.mockito.Mockito.*;
@RunWith(AndroidJUnit4.class)

@ -33,7 +33,7 @@ import org.junit.runner.*;
import java.io.*;
import java.util.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
@RunWith(AndroidJUnit4.class)

@ -34,7 +34,7 @@ import org.junit.runner.*;
import java.util.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.CoreMatchers.*;
@RunWith(AndroidJUnit4.class)
@MediumTest

@ -35,7 +35,7 @@ import org.junit.runner.*;
import java.util.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.core.IsNot.not;
import static org.isoron.uhabits.models.Checkmark.*;

@ -33,8 +33,8 @@ import org.junit.runner.*;
import java.util.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
@SuppressWarnings("JavaDoc")
@RunWith(AndroidJUnit4.class)

@ -32,7 +32,7 @@ import java.util.*;
import static junit.framework.Assert.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.core.IsNot.not;
@RunWith(AndroidJUnit4.class)

@ -30,7 +30,7 @@ import java.io.*;
import static junit.framework.Assert.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.core.IsNot.not;
@RunWith(AndroidJUnit4.class)

@ -29,7 +29,7 @@ import org.junit.*;
import org.junit.runner.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.CoreMatchers.*;
import static org.isoron.uhabits.models.Checkmark.*;
@RunWith(AndroidJUnit4.class)

@ -64,14 +64,14 @@ public abstract class BaseMenu
/**
* Called when the menu is first displayed.
* <p>
* This method cannot be overridden. The application should override the
* methods onCreate(Menu) and getMenuResourceId instead.
* This method should not be overridden. The application should override
* the methods onCreate(Menu) and getMenuResourceId instead.
*
* @param inflater a menu inflater, for creating the menu
* @param menu the menu that is being created.
*/
public final void onCreate(@NonNull MenuInflater inflater,
@NonNull Menu menu)
public void onCreate(@NonNull MenuInflater inflater,
@NonNull Menu menu)
{
menu.clear();
inflater.inflate(getMenuResourceId(), menu);

@ -0,0 +1,81 @@
/*
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.activities;
import android.os.*;
import android.support.v7.widget.Toolbar;
import android.view.*;
import android.widget.*;
import org.isoron.uhabits.*;
import org.junit.*;
import org.junit.runner.*;
import org.robolectric.*;
import org.robolectric.annotation.*;
import static org.mockito.Mockito.*;
import static org.robolectric.Robolectric.*;
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
public class BaseActivityTest
{
@Test
public void menuTest()
{
MenuActivity activity = setupActivity(MenuActivity.class);
verify(activity.baseMenu).onCreate(
eq(activity.getMenuInflater()), any());
Menu menu = activity.toolbar.getMenu();
MenuItem item = menu.getItem(0);
activity.onMenuItemSelected(0, item);
verify(activity.baseMenu).onItemSelected(item);
}
public static class MenuActivity extends BaseActivity
{
public BaseMenu baseMenu;
public Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
toolbar = new Toolbar(this);
LinearLayout layout = new LinearLayout(this);
layout.addView(toolbar);
setContentView(layout);
setSupportActionBar(toolbar);
baseMenu = spy(new BaseMenu(this)
{
@Override
protected int getMenuResourceId()
{
return R.menu.list_habits;
}
});
setBaseMenu(baseMenu);
}
}
}
Loading…
Cancel
Save