package essai; import org.junit.BeforeClass; import org.junit.AfterClass; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.Ignore; import org.junit.Assert; /** * @author lugiez * */ public class EssaiTest { /* * declare some objects used throughout testing */ private Essai essai1; @BeforeClass public static void GeneralsetUp() throws Exception { System.out.print("General setup\n"); } @AfterClass public static void GeneralTearDown() throws Exception { System.out.print("General teardown\n"); } /* /** * @throws Exception * sets some objects to use during tests */ @Before public void setUp() throws Exception { essai1=new Essai(0); System.out.print("Test debut\n"); } /** * @throws Exception * clean up after all testing is done (for instance restoring a DB values) * nothing to do here */ @After public void tearDown() throws Exception { //nothing to do System.out.print("Test effectué\n"); } /** * Test avec asserNotNull: tester que l'objet a été créé * */ @Test public final void testNull(){ Essai essai=essai1; Assert.assertNotNull(essai); } /** * Test method for {@link Essai#getVal()}. * Test pour verifier que le champ a la bonne valeur * */ @Test public void testDefaultAttribute() { Assert.assertEquals(0,essai1.getVal()); } /** * Tester une modification par setVal de 0 en 1 de l'attribut */ @Test public final void testSetVal() { int expected=1; essai1.setVal(1); Assert.assertEquals(expected,essai1.getVal()); } /** * Tester que la modif de 0 en 1 pour l'attribut du test precedent * n'est pas permanente */ @Test public final void testInvariantSetUp() { int shouldnotbeexpected=1; Assert.assertFalse(shouldnotbeexpected==essai1.getVal()); } /** * a test that must fail * */ //@Test @Ignore public final void testGetValWrong(){ essai1.setVal(2); int expected=1; Assert.assertEquals(expected,essai1.getVal()); } /** * a test to skip * */ @Ignore public final void testNotYetImplemented (){ Assert.fail("I should fail"); } @Test public final void testAdd(){ int expected=1; int val=1; Assert.assertTrue("Test 0 neutre",expected==val); } @Test(expected=ArithmeticException.class) public final void testExceptionInverse(){ essai1.setVal(0); float inv=essai1.invVal(); System.out.println(inv); } }