Using assertArrayEquals in unit tests

This would work with JUnit 5:

import static org.junit.jupiter.api.Assertions.*;

assertArrayEquals(new int[]{1,2,3},new int[]{1,2,3});

This should work with JUnit 4:

import static org.junit.Assert.*;
import org.junit.Test;
 
public class JUnitTest {
 
    /** Have JUnit run this test() method. */
    @Test
    public void test() throws Exception {
 
        assertArrayEquals(new int[]{1,2,3},new int[]{1,2,3});
 
    }
}

This is the same for the old JUnit framework (JUnit 3):

import junit.framework.TestCase;

public class JUnitTest extends TestCase {
  public void test() {
    assertArrayEquals(new int[]{1,2,3},new int[]{1,2,3});
  }
}

Note the difference: no Annotations and the test class is a subclass of TestCase (which implements the static assert methods).

Leave a Comment