Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7fbab58
#General updated gradle
Aug 31, 2016
9abd6f8
#Tests added test application and dependency injection at test module
Sep 1, 2016
9e94be4
#Test revrite gallery activity test
Sep 1, 2016
09e004d
#Test fixed ImgurImageActivityTest
Sep 1, 2016
bc82836
#General removed drawable utils
Sep 1, 2016
0dd076f
#Test added preconditions test
Sep 1, 2016
4e253e1
#Test added strings test
Sep 1, 2016
87b9125
#Test added enum preferences test
Sep 1, 2016
a688ac9
#Tests added base presenter test
Sep 2, 2016
43f943d
#Test add activity screen switcher test
Sep 2, 2016
87b7291
#Test added component finder test
Sep 2, 2016
9467cf5
#Test added GalleryDatabase test
Sep 2, 2016
56aa92e
#Test added instant adapter test
Sep 2, 2016
d5c7661
#Test added gallery presenter test
Sep 2, 2016
7600234
#Test gallery view test
Sep 2, 2016
770dac0
#Test restrtucturized tests
Sep 2, 2016
8ef2a56
#Test added mockito dependency
Sep 5, 2016
332b3a8
#Test moved preconditions and enum preferences tests at unit test folder
Sep 5, 2016
0f3d8ff
#Test removed old Activity Rule
Sep 5, 2016
030437d
#Test moved base presenter test at unit test module
Sep 5, 2016
22f7b0c
#Test Modified Enum Preferences test
Sep 5, 2016
046269b
#Test moved instant adapter test to unit test module
Sep 6, 2016
21bd3a5
#Test removed timer test rule
Sep 6, 2016
3f62164
#Test improved gallery tests
Sep 6, 2016
8b78631
Merge remote-tracking branch 'upstream/githup-api' into develop
Sep 12, 2016
8571c7f
#General. Fixed compilation errors
Sep 12, 2016
d16c027
#General Updated support version
Sep 13, 2016
f17b61b
#Test Fixed instrumentation tests launching
Sep 13, 2016
ce7b792
#Test added main activity test
Sep 13, 2016
f8d4404
#Test Added external activity test
Sep 13, 2016
047e74b
#Tests added main view test
Sep 19, 2016
fe49a31
#Tests added base presenter test
Sep 23, 2016
6ec27a9
#General fixed nasty conflict
Sep 23, 2016
f6c95ba
fixed flacky tests
Oct 3, 2016
1badf40
Merge remote-tracking branch 'origin/unit_tests'
Oct 3, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ buildscript {

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.ofg.uptodate'
apply from: '../dependencies.gradle'
apply plugin: 'me.tatarka.retrolambda'

repositories {
mavenCentral()
Expand Down Expand Up @@ -49,8 +49,9 @@ android {
buildConfigField 'String', 'GIT_SHA', "\"${gitSha}\""
buildConfigField 'long', 'GIT_TIMESTAMP', "${gitTimestamp}"


testApplicationId "${versions.packagename}.tests"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "ru.ltst.u2020mvp.U2020InstrumentationRunner"
}

signingConfigs {
Expand Down Expand Up @@ -83,16 +84,6 @@ android {
}
}

// productFlavors {
// internal {
// applicationId "${packagename}.internal"
//
// }
// production {
// applicationId "${packagename}"
// }
// }

lintOptions {
textReport true
textOutput 'stdout'
Expand All @@ -116,6 +107,9 @@ configurations {

configurations.all {
resolutionStrategy {
force "com.android.support:support-annotations:${SUPPORT_V7_VERSION}"
force "com.android.support:recyclerview-v7:${SUPPORT_V7_VERSION}"
force "com.android.support:support-v4:${SUPPORT_V4_VERSION}"
force libraries.supportAnnotation
}
}
Expand Down Expand Up @@ -170,14 +164,14 @@ dependencies {

//-----tests-----
// Espresso 2 Dependencies
androidTestCompile libraries.testingSupportLib
androidTestCompile libraries.junit
androidTestCompile libraries.testRunner
androidTestCompile libraries.testRules
androidTestCompile libraries.espressoCore
// androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.0') {
// exclude module: 'support-annotations'
// }
androidTestApt libraries.daggerCompiler

testCompile libraries.mockito
testCompile libraries.junit
}

// change apk name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ru.ltst.u2020mvp;


public class TestU2020Application extends U2020App {
private TestU2020Component component;

@Override
public void buildComponentAndInject() {
component = DaggerTestU2020Component.builder()
.u2020AppModule(new U2020AppModule(this))
.build();
component.inject(this);
}

@Override
public U2020Component component() {
return component;
}

public TestU2020Component getTestComponent() {
return component;
}
}
18 changes: 18 additions & 0 deletions app/src/androidTest/java/ru/ltst/u2020mvp/TestU2020Component.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.ltst.u2020mvp;

import dagger.Component;
import ru.ltst.u2020mvp.data.DebugDataModule;
import ru.ltst.u2020mvp.ui.DebugUiModule;
import ru.ltst.u2020mvp.ui.ExternalIntentActivityTest;
import ru.ltst.u2020mvp.ui.screen.main.MainActivityTest;
import ru.ltst.u2020mvp.ui.screen.main.view.MainViewTest;

@ApplicationScope
@Component(modules = {U2020AppModule.class, DebugUiModule.class, DebugDataModule.class, TestU2020Module.class})
public interface TestU2020Component extends U2020Component {
void inject(MainActivityTest mainActivityTest);

void inject(ExternalIntentActivityTest externalIntentActivityTest);

void inject(MainViewTest mainViewTest);
}
20 changes: 20 additions & 0 deletions app/src/androidTest/java/ru/ltst/u2020mvp/TestU2020Module.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ru.ltst.u2020mvp;

import dagger.Module;
import dagger.Provides;
import ru.ltst.u2020mvp.ApplicationScope;
import ru.ltst.u2020mvp.IsInstrumentationTest;

@Module
public class TestU2020Module {
// Low-tech flag to force certain debug build behaviors when running in an instrumentation test.
// This value is used in the creation of singletons so it must be set before the graph is created.
static boolean instrumentationTest = true;

@Provides
@ApplicationScope
@IsInstrumentationTest
boolean provideIsInstrumentationTest() {
return instrumentationTest;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ru.ltst.u2020mvp;

import android.app.Application;
import android.content.Context;
import android.support.test.runner.AndroidJUnitRunner;

public class U2020InstrumentationRunner extends AndroidJUnitRunner {
@Override
public Application newApplication(ClassLoader cl, String className, Context context)
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
return super.newApplication(cl, TestU2020Application.class.getName(), context);
}
}
17 changes: 17 additions & 0 deletions app/src/androidTest/java/ru/ltst/u2020mvp/base/BaseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ru.ltst.u2020mvp.base;


import android.support.test.InstrumentationRegistry;

import ru.ltst.u2020mvp.TestU2020Application;
import ru.ltst.u2020mvp.TestU2020Component;

public abstract class BaseTest {
protected TestU2020Application getApp() {
return (TestU2020Application) InstrumentationRegistry.getTargetContext().getApplicationContext();
}

protected TestU2020Component getTestComponent() {
return getApp().getTestComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ru.ltst.u2020mvp.base;

import android.content.Context;
import android.support.test.espresso.matcher.ViewMatchers;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import org.hamcrest.CoreMatchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import ru.ltst.u2020mvp.ui.screen.main.MainActivity;
import ru.ltst.u2020mvp.ui.screen.main.MainScope;

@RunWith(AndroidJUnit4.class)
public class ComponentFinderTest {
@Rule
public ActivityTestRule<MainActivity> activityTestRule = new ActivityTestRule<>(MainActivity.class);

@Test
public void findActivityComponentTest() {
Context context = activityTestRule.getActivity();
ViewMatchers.assertThat(ComponentFinder.findActivityComponent(context),
CoreMatchers.instanceOf(MainScope.MainComponent.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package ru.ltst.u2020mvp.base.mvp;


import android.support.test.espresso.UiController;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;

import ru.ltst.u2020mvp.R;
import ru.ltst.u2020mvp.ui.screen.main.MainActivity;
import ru.ltst.u2020mvp.ui.screen.main.MainPresenter;
import ru.ltst.u2020mvp.ui.screen.main.view.MainView;
import ru.ltst.u2020mvp.util.SimpleViewAction;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

@RunWith(AndroidJUnit4.class)
public class BasePresenterTest2 {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
public ActivityTestRule<MainActivity> activityTestRule =
new ActivityTestRule<>(MainActivity.class);

MainPresenter mainPresenter;

@Before
public void setup() {
mainPresenter = activityTestRule.getActivity().getComponent().presenter();
}

@Test
public void takeView() throws Exception {
assertEquals(true, mainPresenter.hasView());
mainPresenter.getView(); //assert no errors
}

@Test
public void dropView() throws Exception {
expectedException.expect(NullPointerException.class);
mainPresenter.dropView(null);
onView(withId(R.id.main_drawer_layout))
.perform(new SimpleViewAction<MainView>() {
@Override
protected void call(UiController uiController, MainView view) {
mainPresenter.dropView(view);
}
});
assertEquals(false, mainPresenter.hasView());
expectedException.expect(NullPointerException.class);
mainPresenter.getView();
}

@Test
public void hasView() throws Exception {
assertEquals(true, mainPresenter.hasView());
onView(withId(R.id.main_drawer_layout))
.perform(new SimpleViewAction<MainView>() {
@Override
protected void call(UiController uiController, MainView view) {
mainPresenter.dropView(view);
}
});
assertEquals(false, mainPresenter.hasView());
}

@Test
public void getView() throws Exception {
assertNotNull(mainPresenter.getView());
onView(withId(R.id.main_drawer_layout))
.perform(new SimpleViewAction<MainView>() {
@Override
protected void call(UiController uiController, MainView view) {
mainPresenter.dropView(view);
}
});
expectedException.expect(NullPointerException.class);
mainPresenter.getView();
}
}
Loading