aspose file tools*
The moose likes Testing and the fly likes JUnit testing with int[] result Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "JUnit testing with int[] result" Watch "JUnit testing with int[] result" New topic
Author

JUnit testing with int[] result

Larry Frissell
Ranch Hand

Joined: May 16, 2008
Posts: 82
    
    2
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?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29275
    
140

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Larry Frissell
Ranch Hand

Joined: May 16, 2008
Posts: 82
    
    2
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??
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Either missing an import, or not using the version of JUnit you think you are?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29275
    
140

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.*
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Working on your code, you could do:


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JUnit testing with int[] result
 
Similar Threads
Problem: Apache Cactus + Servlet/ControllerTesting + EntityManagerFactory
Concatenate method result , repeat in each Request
Sudoku Solver
What causes this null pointer exception in SortedMap/TreeMap?
session attribute is not setting whenjunit testcase invoked