1

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
  • 1
    You asked this question yesterday at least twice. Commented Sep 29, 2010 at 3:49
  • You should not erase your question after you find the solution. Post it. Commented Oct 15, 2010 at 2:25

3 Answers 3

2

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
Sign up to request clarification or add additional context in comments.

2 Comments

When you do a coverage test in Eclipse, how do you get a better percent?
@Brian, this seems like an unrelated question, but the answer would be: write more tests that cover the uncovered code.
2

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.