Skip to content

Commit 8209ac8

Browse files
avoid running the tests when the input is not present in the CI pipeline
Took 4 minutes
1 parent 1f0458c commit 8209ac8

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/test/java/aminetti/adventofcode2024/day06/Day06Test.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package aminetti.adventofcode2024.day06;
22

33
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.api.condition.EnabledIf;
45

56
import java.io.IOException;
67
import java.util.List;
@@ -14,7 +15,7 @@
1415

1516
class Day06Test {
1617

17-
@Test
18+
@Test @EnabledIf("inputExists")
1819
void actualInputPart1() throws IOException {
1920
// given
2021
List<String> input = readLines(resourceToString("/day06/day06_input.txt", UTF_8));
@@ -42,7 +43,7 @@ void testInputPart1() throws IOException {
4243
assertThat(l, is(41L));
4344
}
4445

45-
@Test
46+
@Test @EnabledIf("inputExists")
4647
void actualInputPart2() throws IOException {
4748
// given
4849
List<String> input = readLines(resourceToString("/day06/day06_input.txt", UTF_8));
@@ -72,5 +73,7 @@ void testInputPart2() throws IOException {
7273
assertThat(l, is(6L));
7374
}
7475

75-
76+
public static boolean inputExists() {
77+
return Day06Test.class.getResource("/dayXX/dayXX_input.txt") != null;
78+
}
7679
}

src/test/java/aminetti/adventofcode2024/dayXX/DayXXTest.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package aminetti.adventofcode2024.dayXX;
22

33
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.api.condition.EnabledIf;
45

56
import java.io.IOException;
67
import java.util.List;
@@ -13,7 +14,7 @@
1314

1415
class DayXXTest {
1516

16-
@Test
17+
@Test @EnabledIf("inputExists")
1718
void actualInputPart1() throws IOException {
1819
// given
1920
List<String> input = readLines(resourceToString("/dayXX/dayXX_input.txt", UTF_8));
@@ -41,7 +42,7 @@ void testInputPart1() throws IOException {
4142
assertThat(l, is(0L));
4243
}
4344

44-
@Test
45+
@Test @EnabledIf("inputExists")
4546
void actualInputPart2() throws IOException {
4647
// given
4748
List<String> input = readLines(resourceToString("/dayXX/dayXX_input.txt", UTF_8));
@@ -69,5 +70,7 @@ void testInputPart2() throws IOException {
6970
assertThat(l, is(0L));
7071
}
7172

72-
73+
public static boolean inputExists() {
74+
return DayXXTest.class.getResource("/dayXX/dayXX_input.txt") != null;
75+
}
7376
}

src/test/resources/dayXX/dayXX_input.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)