| Author |
expected:5 but was:5.0000000
|
miguel lisboa
Ranch Hand
Joined: Feb 08, 2004
Posts: 1281
|
|
i'm sure i've read the solution to this somewhere but just cant find it...
junit.framework.AssertionFailedError: expected:<5> but was:<5.000000000000000000000000000000> at junit.framework.Assert.fail(Assert.java:47) at junit.framework.Assert.failNotEquals(Assert.java:282) at junit.framework.Assert.assertEquals(Assert.java:64) at junit.framework.Assert.assertEquals(Assert.java:71) at bd.CenarioTest.testAm(CenarioTest.java:165) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
i'm using java5, hibernate2 and mysql4; if instead i use hsql all is fine, but with mysql i get this junit error: how can i turn this around? if i view database table, 5.00000000... indeed appears just like that, instead of, simply, 5! TiA
|
java amateur
|
 |
Lasse Koskela
author
Sheriff
Joined: Jan 23, 2002
Posts: 11962
|
|
What is the Java type returned from "am.getPagoPeloUtente()" and what is the data type for that whatever it is in the database column? In any case, try comparing the primitive values of the BigDecimal and the other number object. For example, using BigDecimal#longValue(), or BigDecimal#doubleValue() with the help of the third argument for assertEquals(double expected, double actual, double allowedDiff).
|
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
|
 |
miguel lisboa
Ranch Hand
Joined: Feb 08, 2004
Posts: 1281
|
|
Originally posted by Lasse Koskela: What is the Java type returned from "am.getPagoPeloUtente()" and what is the data type for that whatever it is in the database column?
returned dataType is BigDecimal in mysql, when generated by hibernate is: pagoPeloUtente numeric and in mysql appears like: DECIMAL(31,30) [ February 15, 2006: Message edited by: miguel lisboa ]
|
 |
miguel lisboa
Ranch Hand
Joined: Feb 08, 2004
Posts: 1281
|
|
in the meanwhile i tried your suggestion and it worked: but what i remember is that one could change i dont know what at mysql table fileds so that big decimal 5 is stored as 5 and not as 5.00000000000000..... thanks for the idea, anyway
|
 |
Balazs Borbely
Ranch Hand
Joined: Oct 11, 2004
Posts: 33
|
|
assertEquals(Object obj1, Object obj2) uses the equalsmethod. But new BigDecimal("2").equals(new BigDecimal("2.0") is false because the equals takes in consideration the scale as well. Possible solutions: 1. use assertTrue(num1.compareTo(num2)==0); 2. set the same scale for both numbers
|
'Make everything as simple as possible, but not simpler.' --Albert Einstein
|
 |
 |
|
|
subject: expected:5 but was:5.0000000
|
|
|