-3

hi there I am trying to test my code java code with JUnit test case
but there is a problem with the tester I don't know what it is, happy to get from your review and guides

here is the code>>

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

class Ex2_Test {
static double[] po1={2,0,3, -1,0}, 
        po2 = {0.1,0,1, 0.1,3};
static final double EPS = 0.0001;

@Test
void testF() {
    double fx0 = Ex2.f(po1, 0);
    double fx1 = Ex2.f(po1, 1);
    double fx2 = Ex2.f(po1, 2);
    assertEquals()
    assertEquals(fx0,2);
    assertEquals(fx1,4);
    assertEquals(fx2,6);
}



@Test
void testRoot() {
    double x12 = Ex2.root(po1, 0, 10, EPS);
    assertEquals(x12, 3.1958, 0.001);
}

@Test
void testDerivativeArrayDoubleArray() {
    double[] p = {1,2,3}; // 3X^2+2x+1
    double[] dp1 = {2,6}; // 6x+2
    double[] dp2 = Ex2.derivative(p);
    assertEquals(dp1[0], dp2[0],EPS);
    assertEquals(dp1[1], dp2[1],EPS);
    assertEquals(dp1.length, dp2.length);
}
}

and here is the errors messages>>

The method assertEquals() is undefined for the type Ex2_Test The import org.junit cannot be resolved

The method assertEquals(double, int) is undefined for the type Ex2_Test

The method assertEquals(double, int) is undefined for the type Ex2_Test

Test cannot be resolved to a type

Test cannot be resolved to a type

The method assertEquals(double, double, double) is undefined for the type Ex2_Test

The method assertEquals(int, int) is undefined for the type Ex2_Test

The method assertEquals(double, double, double) is undefined for the type Ex2_Test

please check the image here>>

here is the tester

loai shark
  • 23
  • 4

2 Answers2

2
  1. Download JUnit.jar and add it to referenced library;

  2. Add the following import sentences;

     import org.junit.Test;
     import static org.junit.Assert.*;
    

About testing, you can refer to Testing Java with Visual Studio Code.

Molly Wang
  • 2,246
  • 1
  • 1
  • 9
0
  1. Check you added package the jUnit.jar or testNG.rar
  2. Import sentences: import org.junit.Test; import static org.junit.Assert.*;
Thân LƯƠNG
  • 2,269
  • 2
  • 9
  • 13
  • check this image >>https://prnt.sc/w3g6ei it is testing the function sum return x+y here but there is an error here are the tester result >> https://prnt.sc/w3g7q5 – loai shark Dec 15 '20 at 20:09