• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JUnit testing with int[] result

 
Ranch Hand
Posts: 82
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am testing a method that has a string input and returns an int[] (see code below)
The assert fails because the int[] expResult = {2010,1,23} is a different Object, if I manually test each int in the two arrays, I will see they are the same value.



My question is for JUnit testing do you have to override the assertEquals when comparing arrays?
 
author & internet detective
Posts: 41919
910
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Larry,
In JUnit 4, a method called assertArrayEquals() was introduced. It is overloaded for all primitives and objects. It was introduced just for this purpose.
 
Larry Frissell
Ranch Hand
Posts: 82
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, I did find that on the JUnit.org site while I was searching for a solution. However, I keep getting compile errors

cannot find symbol
symbol : method assertArrayEquals(int[],int[])
location: class mvc.DateEntryFormatterunit4Test
assertArrayEquals(expResult, result);
1 error



I am using NetBeans 6.9, I have JUnit 4.5 in the library and the JDK 1.6 on a mac.

I am not sure now what the problem is??
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Either missing an import, or not using the version of JUnit you think you are?
 
Jeanne Boyarsky
author & internet detective
Posts: 41919
910
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Larry,
You can be using JUnit 4.X but still using the JUnit 3.8 assert class. Check your static import is for org.junit.Assert.* rather than junit.framework.Assert.*
 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Working on your code, you could do:

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic