Last active
August 29, 2015 14:25
-
-
Save quentin7b/9b1389bdcf00018f276d to your computer and use it in GitHub Desktop.
[Robolectric / Jacoco] Test Example
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
import org.junit.Rule; | |
import org.junit.Test; | |
import org.junit.rules.ErrorCollector; | |
import org.junit.runner.RunWith; | |
import org.robolectric.RobolectricGradleTestRunner; | |
import org.robolectric.annotation.Config; | |
import static org.hamcrest.CoreMatchers.equalTo; | |
import static org.hamcrest.CoreMatchers.not; | |
/** | |
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | |
* Example of a Test class <br /> | |
* BuildConfig | |
*/ | |
@RunWith(RobolectricGradleTestRunner.class) | |
@Config(constants = BuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml") | |
public class TestMyObject { | |
/** | |
* The collector is used to prevent tests to stop if a fail is found. | |
*/ | |
@Rule | |
public ErrorCollector collector = new ErrorCollector(); | |
/** | |
* Test the empty constructor (default one) | |
*/ | |
@Test | |
public void testEmptyConstructor() { | |
MyObject object = new MyObject(); | |
MyObject otherObject = new MyObject(1, 2, 3); | |
// Some way to test your constructor. Might check the initialization of the fields ;) | |
collector.checkThat(object, not(equalTo(otherObject))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment