Latest videos

Categories > JUnit tutorial > JUnit assertions methods

JUnit assertions methods


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

Recommended materials

Share / Subscribe


Free online web Java example projects

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



Created by , professional Java and Oracle DB trainer. All Rights Reserved.

Other projects

This web site is monitored by FOSS Site monitoring application

My GitHub account