dimanche 27 décembre 2015

Why 'assert' is not failing in junit test

I used 'assert' in my code.

@RunWith(PowerMockRunner.class)
@PrepareForTest({ Puppy.class })
public class PuppyTest {

    @Test
    public void testCreatePuppy() {
        // Mocking
        Human human = Mockito.mock(Human.class);
        Puppy puppy = Puppy.createPuppy("Gatsby", human);
        assert(null!=puppy);
        assert("Gatsby1".equals(puppy.getName()));
        assert false;   //This should fail anyway
    }

  .....

} 

But , assert is not failing even for falsy conditions. If I use Assert class methods, it is working as expected.

  @Test
    public void testCreatePuppy() {
        // Mocking
        Human human = Mockito.mock(Human.class);
        Puppy puppy = Puppy.createPuppy("Gatsby", human);
        Assert.assertNotNull(puppy);
        Assert.assertEquals("Gatsby1",puppy.getName());
  }

Can't we use assert in Junit test cases ?

Aucun commentaire:

Enregistrer un commentaire