views:

91

answers:

3
+1  Q: 

Java Unit Testing

I am trying to do some Unit Testing on my program and I need to test if an array is equal to another array so I need to write the code for Assert.assertArrayEquals(a2, a3), what would this code look like?

PS: I release this function is available in JUnit 4 but I don't have a new enough version for the provided function to work so I need to get code for one I got add to my tests.

Thanks

+2  A: 

The great thing about open source projects is that when you are curious how something works, you can just open up the source code and read it yourself.

Here is a hint on what conditions you would probably want to have met to consider two arrays "equal"

  • Both arrays have the same length
  • Both arrays have the same value at the same index
matt b
When you do a coverage test in Eclipse, how do you get a better percent?
user258875
@Brian, this seems like an unrelated question, but the answer would be: write more tests that cover the uncovered code.
matt b
A: 

hi Brain, to achieve above, u can use assertArrayEquals for org.junit.Assert, that will work for you, and if u want to implement in your own way, then you can write simple code to compare each element of the array in a simple for loop.

Mrityunjay
+2  A: 

you can use Arrays.equals(a2, a3) method available in the Arrays class java.util pacakge

hakish