I'm creating some Junit Tests with Android Studio 1.2.2. This is my TestClass. It extends from ActivityTestCase (or InstrumentationTestCase).
public class TypeTest extends ActivityTestCase
{
TypesMeth typesMeth = new TypesMeth();
public void testTypes()
{
typesMeth.setValue((short) 1000000);
assertEquals(exception, typesMeth.getValue());
}
}
The parameter must be short. So the range is from -32768 to 32767.
If I pass a value of 1000000 it should throw an exception and the test should be passed.
How can I check that? Something like: assertExceptionIsThrown(true, typesMeth.getValue());
In classical JUnit 4 you would add some annotation before your testcase
As far as I know there are no annotation in Android which support this, so you need to do it in a pre JUnit 4 way with try and catch