Your vote counts! solves your problems. In order to continue,
we must focus our resources. Please tell us which topics
you would like to cover:

JUnit assertions methods

JUnit assertions methods: assertEquals, assertSame, assertNull, assertNotNull, assertTrue, assertFalse explained.

There are several JUnit assertion methods and they are all static methods defined in org.junit.Assert class. You can easily use them if you do import static org.junit.Assert.*;

  • fail() - fails test
  • assertNotNull(o) / assertNull(o) - assert if object is (not) null
  • assertFalse(b) / assertTrue(b) - asserts if b is false / true
  • assertEquals(a, b) - compares two objects using equals() method: a.equals(b)
  • assertSame(a, b) - compares two objects using == operator:  a == b
  • assertArrayEquals(a, b) - compares two arrays
  • assertThat(o, condition) - asserts that o satisfies the condition specified by an instance of org.hamcrest.Matcher

comments powered by Disqus

Share / Subscribe



Free online Java web application examples

Want to develop whole web applications which use database, security and more? See my github account, where are lot's of example projects: