Skip to content

Instantly share code, notes, and snippets.

@quentin7b
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quentin7b/9b1389bdcf00018f276d to your computer and use it in GitHub Desktop.
Save quentin7b/9b1389bdcf00018f276d to your computer and use it in GitHub Desktop.
[Robolectric / Jacoco] Test Example
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