toogle sidebar button

JUnit

Dependencies

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
    <scope>test</scope>
</dependency>

Mockito

Dependencies

mockito-core

<!-- needs extra dependencies: objenesis & hamcrest -->
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>

mockito-all

<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>

##JRunner

@RunWith(MockitoJUnitRunner.class)

#Hamcrest Matchers ##Refs

  • http://java.dzone.com/articles/hamcrest-containing-matchers

Dependencies

<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest-all</artifactId>
    <version>1.3</version>
    <scope>test</scope>
</dependency>

Fest

Dependency:

<dependency>
  <groupId>org.easytesting</groupId>
  <artifactId>fest-assert</artifactId>
  <version>1.4</version>
</dependency>

Import:

import static org.fest.assertions.Assertions.assertThat;

Use:

public void testMain() {
    List<String> dummyList = Arrays.asList("a","b","c");
    assertThat(dummyList).containsOnly("a","c","b");
}

AssertJ

Dependency:

<dependency>
  <groupId>org.assertj</groupId>
  <artifactId>assertj-core</artifactId>
  <!-- use 3.1.0 for Java 8 projects -->
  <version>2.2.0</version>
  <scope>test</scope>
</dependency>

Import:

import static org.assertj.core.api.Assertions.*;

Use:

public void testMain() {
    List<String> dummyList = Arrays.asList("a","b","c");
    assertThat(dummyList).containsOnly("a","c","b");
}

Reference: