import org.junit.runner.JUnitCore;import org.junit.runner.Result;import org.junit.runner.notification.Failure; public class AssertEqualExceptionMethod { public static void main(String[] args) { Result result = JUnitCore.runClasses( AssertEqualExceptionMethodTest.class ); for(Failure failure : result.getFailures()) { System.out.println( failure.toString() ); } System.out.println( result.wasSuccessful() ); } }
import org.junit.Test; import static org.junit.Assert.assertEquals; /** * Created by Divakar on 2/16/2017. */public class AssertEqualExceptionMethodTest { @Test(expected = ArrayIndexOutOfBoundsException.class) public void valueEquality() throws InterruptedException { int z=0; int[] no = {1,2,3,4,5}; // TRUE, when found 'ArrayIndexOutOfBoundsException' error for(int i = 0; i<10; i++) { z = no[i]; } // FALSE, when found any other error /*for(int i = 0; i<10; i++) { z = no[i]; }*/ assertEquals(4, z); } }
22
No comments:
Post a Comment