mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2025-06-05 21:49:13 +02:00
setup Robolectric for tests
This commit is contained in:
@@ -21,7 +21,9 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
testCompile 'junit:junit:4.12'
|
|
||||||
compile 'com.android.support:appcompat-v7:23.1.1'
|
compile 'com.android.support:appcompat-v7:23.1.1'
|
||||||
compile 'com.jakewharton:butterknife:7.0.1'
|
compile 'com.jakewharton:butterknife:7.0.1'
|
||||||
|
|
||||||
|
testCompile 'junit:junit:4.12'
|
||||||
|
testCompile "org.robolectric:robolectric:3.0"
|
||||||
}
|
}
|
||||||
|
2
app/src/main/project.properties
Normal file
2
app/src/main/project.properties
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
android.library.reference.1=../../build/intermediates/exploded-aar/com.android.support/support-v4/23.1.1
|
||||||
|
android.library.reference.2=../../build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.1
|
@@ -1,15 +0,0 @@
|
|||||||
package calculator.simplemobiletools.com.simple_calculator;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* To work on unit tests, switch the Test Artifact in the Build Variants view.
|
|
||||||
*/
|
|
||||||
public class ExampleUnitTest {
|
|
||||||
@Test
|
|
||||||
public void addition_isCorrect() throws Exception {
|
|
||||||
assertEquals(4, 2 + 2);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,17 @@
|
|||||||
|
package calculator.simplemobiletools.com.simple_calculator;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.Robolectric;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
@RunWith(MyTestRunner.class)
|
||||||
|
@Config(constants = BuildConfig.class, manifest = "app/src/main/AndroidManifest.xml", sdk = 21)
|
||||||
|
public class MainActivityTest {
|
||||||
|
MainActivity activity;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
activity = Robolectric.setupActivity(MainActivity.class);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,22 @@
|
|||||||
|
package calculator.simplemobiletools.com.simple_calculator;
|
||||||
|
|
||||||
|
import org.junit.runners.model.InitializationError;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.manifest.AndroidManifest;
|
||||||
|
import org.robolectric.res.Fs;
|
||||||
|
|
||||||
|
public class MyTestRunner extends RobolectricTestRunner {
|
||||||
|
|
||||||
|
public MyTestRunner(Class<?> testClass) throws InitializationError {
|
||||||
|
super(testClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AndroidManifest getAppManifest(Config config) {
|
||||||
|
return new AndroidManifest(
|
||||||
|
Fs.fileFromPath("../app/src/main/AndroidManifest.xml"),
|
||||||
|
Fs.fileFromPath("../app/src/main/res"),
|
||||||
|
Fs.fileFromPath("../app/src/main/assets"));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user