Created
June 6, 2017 18:08
-
-
Save btow/9fecce2738eef344b5e36381bba17b9e to your computer and use it in GitHub Desktop.
Bad Android Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
// Create a variable called keystorePropertiesFile, and initialize it to your | |
// keystore.properties file, in the rootProject folder. | |
def keystorePropertiesFile = rootProject.file("keystore.properties") | |
// Initialize a new Properties() object called keystoreProperties. | |
def keystoreProperties = new Properties() | |
// Load your keystore.properties file into the keystoreProperties object. | |
keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) | |
android { | |
signingConfigs { | |
freeSign { | |
keyAlias keystoreProperties['keyAlias'] | |
keyPassword keystoreProperties['keyPassword'] | |
storeFile file(keystoreProperties['storeFile']) | |
storePassword keystoreProperties['storePassword'] | |
} | |
} | |
compileSdkVersion 25 | |
buildToolsVersion "25.0.2" | |
defaultConfig { | |
applicationId "com.example.samsung.gps_coordinate_determiner" | |
minSdkVersion 10 | |
targetSdkVersion 25 | |
versionCode 1 | |
versionName "1.0" | |
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
signingConfig signingConfigs.freeSign | |
} | |
debug { | |
} | |
} | |
testOptions { | |
unitTests { | |
returnDefaultValues = true | |
} | |
} | |
} | |
def support = '25.3.1' | |
def moxy = '1.5.3' | |
def butterKnife = '8.6.0' | |
dependencies { | |
compile fileTree(include: ['*.jar'], dir: 'libs') | |
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | |
exclude group: 'com.android.support', module: 'support-annotations' | |
}) | |
compile "com.android.support:appcompat-v7:$support" | |
compile "com.android.support:support-v4:$support" | |
compile "com.arello-mobile:moxy:$moxy" | |
compile "com.arello-mobile:moxy-app-compat:$moxy" | |
annotationProcessor "com.arello-mobile:moxy-compiler:$moxy" | |
compile "com.jakewharton:butterknife:$butterKnife" | |
annotationProcessor "com.jakewharton:butterknife-compiler:$butterKnife" | |
testCompile 'junit:junit:4.12' | |
testCompile 'org.mockito:mockito-core:1.10.19' | |
androidTestCompile "com.android.support:support-annotations:$support" | |
androidTestCompile 'com.android.support.test:runner:0.5' | |
androidTestCompile 'com.android.support.test:rules:0.5' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.samsung.gps_coordinate_determiner; | |
import android.content.Context; | |
import android.support.test.InstrumentationRegistry; | |
import android.support.test.runner.AndroidJUnit4; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import static junit.framework.Assert.assertEquals; | |
import static org.junit.Assert.*; | |
/** | |
* Instrumentation test, which will execute on an Android device. | |
* | |
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | |
*/ | |
@RunWith(AndroidJUnit4.class) | |
public class ExampleInstrumentedTest { | |
@Test | |
public void useAppContext() throws Exception { | |
// Context of the app under test. | |
Context appContext = InstrumentationRegistry.getTargetContext(); | |
assertEquals("com.example.samsung.gps_coordinate_determiner", appContext.getPackageName()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.samsung.gps_coordinate_determiner.presentation.presenter.main; | |
import android.content.Context; | |
import android.location.Location; | |
import android.location.LocationManager; | |
import android.support.test.runner.AndroidJUnit4; | |
import android.test.AndroidTestCase; | |
import android.test.mock.MockContext; | |
import com.example.samsung.gps_coordinate_determiner.R; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import java.util.HashMap; | |
import java.util.Map; | |
import static org.junit.Assert.*; | |
/** | |
* Created by | |
* | |
* @autor Vladimir Bobkov | |
* on 29.05.2017. | |
*/ | |
@SuppressWarnings("deprecation") | |
public class MainPresenterTest extends AndroidTestCase { | |
Context mCxt; | |
@RunWith(AndroidJUnit4.class) | |
public void onClickBtn() throws Exception { | |
} | |
@Test | |
public void getStringLocation() throws Exception { | |
} | |
@Override | |
protected void setUp() throws Exception { | |
super.setUp(); | |
mCxt = new MockContext(); | |
setContext(mCxt); | |
assertNotNull(mCxt); | |
} | |
@Test | |
public void getStringLocationTest() { | |
String assertValue = mCxt.getString(R.string.given_accuracy_is_impossible); | |
Location[] locations = {new Location(LocationManager.GPS_PROVIDER), | |
new Location(LocationManager.GPS_PROVIDER), | |
new Location(LocationManager.GPS_PROVIDER)}; | |
locations[0].setLatitude(5000); | |
locations[0].setLongitude(5000); | |
locations[0].setAccuracy(13.5f); | |
locations[1].setLatitude(15000); | |
locations[1].setLongitude(15000); | |
locations[1].setAccuracy(60.5f); | |
Map<Location, String> values = new HashMap<>(); | |
for (Location location : | |
locations) { | |
if (location == null) { | |
assertValue = mCxt.getString(R.string.location_is_not_defined); | |
} else if (location.getAccuracy() < 60) { | |
assertValue = mCxt.getString(R.string.position_coordinates) + " " | |
+ mCxt.getString(R.string.lat) + " = " + location.getLatitude() + ", " | |
+ mCxt.getString(R.string.lon) + " = " + location.getLongitude() + ", " | |
+ mCxt.getString(R.string.accuracy) + " = " + location.getAccuracy(); | |
} else if (location.getAccuracy() >= 60) { | |
assertValue = mCxt.getString(R.string.given_accuracy_is_impossible); | |
} | |
values.put(location, assertValue); | |
} | |
MainPresenter mMainPresenter = new MainPresenter(); | |
for (Map.Entry<Location, String> value : | |
values.entrySet()) { | |
Assert.assertEquals(value.getValue(), mMainPresenter.getStringLocation(value.getKey())); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment