Итак, хотя начальные значения были разными, тестовый код и ожидаемое значение были точно такими же. Однако мои тесты оказались тремя функциями с одним и тем же кодом, что беспокоило SonarCloud.
Пример:
Код: Выделить всё
@Sql(scripts = {"classpath:data/db/condition_negative.sql"})
@Test
void testConditionNegative() {
[some code to get the actual value]
Assertions.assertEquals(actual, 0);
}
@Sql(scripts = {"classpath:data/db/condition_null.sql"})
@Test
void testConditionNull() {
[some code to get the actual value]
Assertions.assertEquals(actual, 0);
}
@Test
void testConditionNoRecords() {
[some code to get the actual value]
Assertions.assertEquals(actual, 0);
}
Пример вышесказанного:
Код: Выделить всё
private void sharedTestFunction() {
[some code to get the actual value]
Assertions.assertEquals(actual, 0);
}
@Sql(scripts = {"classpath:data/db/condition_negative.sql"})
@Test
void testConditionNegative() {
sharedTestFunction();
}
@Sql(scripts = {"classpath:data/db/condition_null.sql"})
@Test
void testConditionNull() {
sharedTestFunction();
}
@Test
void testConditionNoRecords() {
sharedTestFunction();
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... -each-time