Issue
I'm trying to write a test case where my scenario is that two byte arrays should be not equal.
Can I do this with junit?
Or do I have to use something external like Hamcrest? href="https://stackoverflow.com/questions/1096650/why-doesnt-junit-provide-assertnotequals-methods/1464411#1464411">I couldn't change the code in this answer to do the job
Please give a sample.
Solution
I prefer doing this the Hamcrest way, which is more expressive:
Assert.assertThat(array1, IsNot.not(IsEqual.equalTo(array2)));
Or the short version with static imports:
assertThat(array1, not(equalTo(array2)));
(The IsEqual
matcher is smart enough to understand arrays, fortunately.)
Note that a limited version of Hamcrest is part of the JUnit 4.x distribution, so you don't need to add an external library.
Answered By - Sean Patrick Floyd
Answer Checked By - Candace Johnson (JavaFixing Volunteer)