Cannot find symbol assertEquals

Viewed 110521

I'm trying to write my first unit tests for a calculator, but NetBeans says it can't find the symbol assertEquals and annotation @Test.
Should i include something?
I'm using NetBeans 7.3.1 and W7.

package calculator;

import org.junit.Assert.*;

public class UnitTests{

    @Test
    public void checkAdd(){
        assertEquals(2, Calculator.rpnCalc(" 2 3 + "));
    }
}

EDIT: Thanks guys, importing it as static helped. Test annotation required only including

import org.junit.Test;

7 Answers

I was having the same problem cannot resolve symbol Assert i have tried these solutions by adding the different import from the different answers.

  1. import org.junit.Assert;
  2. import static org.junit.Assert.*;
  3. import static org.junit.Assert.assertEquals;
  4. import static org.junit.jupiter.api.Assertions.*;
  5. import org.junit.Assert;

but the solution that did the magic was just place the junit-4.12.jar in the app\lib ditectory and just build the project, and import like this

import org.junit.Assert;

you can download the junit-4.12.jar from here

Using IntelliJ 2019.2.4 with a start.sping.io default setup...

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

but now instead of

Assert.assertEquals(expected, actual);

use

assertEquals(expected, actual);

You have to add the dependency to pom.xml file

<dependency>
  <groupId>junit</groupId>          
  <artifactId>junit</artifactId>            
  <version>4.12</version>       
</dependency>

my project is based at maven,although I editor junit in the pom.xml,I still can't find junit in my repository,so I download the junit.jar into my repository.It works!you can try it!

Related