Skip to content
Advertisement

Tag: assertions

Comparing arrays in JUnit assertions, concise built-in way?

Is there a concise, built-in way to do equals assertions on two like-typed arrays in JUnit? By default (at least in JUnit 4) it seems to do an instance compare on the array object itself. EG, doesn’t work: Of course, I can do it manually with: ..but is there a better way? Answer Use org.junit.Assert’s method assertArrayEquals: If this method

What does the Java assert keyword do, and when should it be used?

What are some real life examples to understand the key role of assertions? Answer Assertions (by way of the assert keyword) were added in Java 1.4. They are used to verify the correctness of an invariant in the code. They should never be triggered in production code, and are indicative of a bug or misuse of a code path. They

Advertisement