-
Notifications
You must be signed in to change notification settings - Fork 0
Junit5 β Repeated tests
Devrath edited this page Oct 23, 2023
·
2 revisions
@RepeatedTest(100)
fun `Add multiple products, total price sum is correct`(){
val productOne = Product(id = 1, name = "Product-1", price = 1.0)
val productTwo = Product(id = 2, name = "Product-2", price = 2.0)
cart.addProduct(productOne,1)
cart.addProduct(productTwo,1)
assertThat(cart.getTotalCost()).isEqualTo(3.0)
}
- We can use
@RepeatedTest(100)
for example to run a test 100 times or any number of times needed. - This ensures that the test is successful all the number of times.
- It is especially useful because it helps to identify the
flaky
tests. -
Flaky
tests are the tests that run sometimes and fail sometimes.
![Screenshot 2023-10-23 at 11 39 02β―PM](https://private-user-images.githubusercontent.com/1456191/277433738-906f798e-89ed-44a9-888b-abd19e4f8160.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxMzc2MjYsIm5iZiI6MTczOTEzNzMyNiwicGF0aCI6Ii8xNDU2MTkxLzI3NzQzMzczOC05MDZmNzk4ZS04OWVkLTQ0YTktODg4Yi1hYmQxOWU0ZjgxNjAucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDlUMjE0MjA2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MmU1NDVhMGEyODI1YTkxYjc3MjhjZjJkNjYxZGFmMDBjZGRlNGNlMjYwMTBlMGI1ODFlZjcxMDBiNTJlNWJjOSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.UbI8IsEb9RKLVFVQHxizQO_i0TE3Js240fwq0L_njLU)