0
package Jut;
import org.junit.*;
import static org.junit.Assert.*;

public class JUTest {


@Test  
public void testDoubleComparison() {  

    double expected = 10.20;  
    double actual = 10.20;  

    assertEquals(expected, actual, 0.0);  
}  

}  

Test Run says: No test passed, 1 test failed: The test case is a prototype. (junit.framework.AssertionFailedError)

But I'm sure this will works fine. Why it doesn't passed? I'm using Netbeans and the newest Junit (I think 4.10?).

EchoCache
  • 555
  • 2
  • 8
  • 22

3 Answers3

1

"assertEquals" fails because the values are double

You can try using some value > 0 for epsilon

assertEquals(double expected, double actual, double epsilon)

So that will assert to true as long as Math.abs(expected - actual) < epsilon

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
v.coder
  • 1,822
  • 2
  • 15
  • 24
  • can you try a smaller value like 0.01 for eplison – v.coder Mar 23 '15 at 21:28
  • Similar question has been asked previously in http://stackoverflow.com/questions/5939788/junit-assertequalsdouble-expected-double-actual-double-epsilon. As stated in it, eplison describes how close you need the double values to be. – v.coder Mar 23 '15 at 21:37
  • it gives me the same failure message (prototype)... assertEquals(10.24, 10.24, 0.01)... – EchoCache Mar 23 '15 at 22:13
  • int expected = 10; int actual = 10; assertEquals(expected, actual); doesen't work, too. – EchoCache Mar 23 '15 at 22:16
  • So on: assertEquals(12, 12); gives me the test case is a prototype? I think long values are valid in Junit 4.10. – EchoCache Mar 23 '15 at 22:26
  • Can you paste the failure message – v.coder Mar 23 '15 at 22:27
0
public void testComprovaNumero() {
    System.out.println("comprovaNumero");
    double num = 0.0;
    checknum instance = new checknum();
    double expResult = 0.0;
    double result = instance.comprovaNumero(num);
    assertEquals(expResult, result, 0.0);
    // fail("The test case is a prototype."); ----> Commenting on this line of code is what made the problem disappear

}

I hope it works for someone!

-1

Nothing's wrong with your test. I've tried with JUnit 4.12 and Netbeans IDE 8.2 and test passes. I also think it's a bug.