Course notes taken for CSCB07/CSC207 at UofT (Software Design).

Introduction to JUnit.

Unit Testing Overview

Unit testing is testing bits of your code in isolation.

A unit can be viewed as the smallest testable part of an application.


Test Suites

There are two main ways to test:

There is a major disadvantage of writing a test suite:



Nice function to use, but just a warning, if inputs are primitives, it will use ==, however if are objects, it will use the .equals method.

Sample Unit Test

package test;

import static org.junit.Assert.assertEquals;

import matrix.comparator.ComparisonType;
import org.junit.Test;

public class ComparisonTypeTest {

  public void testShouldHaveMAX() {
    assertEquals(ComparisonType.MAX, ComparisonType.MAX);

  public void testShouldHaveMIN() {
    assertEquals(ComparisonType.MIN, ComparisonType.MIN);