Assertions Flashcards

1
Q

Packages to import

A

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Example

A

@Test
void exampleTest() {
int result = someMethod();
Assertions.assertEquals(42, result, “The result should be 42”);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Common Assertions

A

assertEquals(expected, actual): Checks if two values are equal.
assertTrue(condition): Checks if a condition is true.
assertFalse(condition): Checks if a condition is false.
assertNotNull(object): Checks if an object is not null.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Parameterized Tests

A

This Parameterized Test is used to test a Test case with different parameters for this we use @ParameterizedTest annotations.

@ParameterizedTest
@ValueSource(ints = {1, 2, 3, 4, 5})
void testSquare(int value) {
int result = square(value);
assertEquals(value * value, result, “Square calculation is incorrect”);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly