This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JUnit testing with int[] result

 
Ranch Hand
Posts: 82
2
  • Mark post as helpful
  • send pies
  • 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: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Working on your code, you could do:

 
    Bookmark Topic Watch Topic
  • New Topic