Advertisement
metalni

JUnit Input Space Partitioning

Mar 27th, 2022
1,212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.32 KB | None | 0 0
  1. import org.junit.jupiter.params.ParameterizedTest;
  2. import org.junit.jupiter.params.provider.Arguments;
  3. import org.junit.jupiter.params.provider.MethodSource;
  4. import java.util.Arrays;
  5. import java.util.List;
  6. import java.util.stream.Stream;
  7.  
  8. import static org.junit.jupiter.api.Assertions.*;
  9.  
  10. class SKITH1Test {
  11.  
  12.     // Interface-based tests
  13.     @ParameterizedTest
  14.     @MethodSource("generateTest1Data")
  15.     void test1(List<String> list1, List<String> list2) {
  16.         List<String> result = SKITH1.commonElements(list1, list2);
  17.         assertTrue(result == null || result.size() > 0);
  18.     }
  19.  
  20.     @ParameterizedTest
  21.     @MethodSource("generateTest2Data")
  22.     void test2(List<String> list1, List<String> list2) {
  23.         assertNull(SKITH1.commonElements(list1, list2));
  24.     }
  25.  
  26.     @ParameterizedTest
  27.     @MethodSource("generateTest3Data")
  28.     void test3(List<String> list1, List<String> list2) {
  29.         assertThrows(NullPointerException.class, () -> SKITH1.commonElements(list1, list2));
  30.     }
  31.  
  32.     @ParameterizedTest
  33.     @MethodSource("generateTest4Data")
  34.     void test4(List<String> list1, List<String> list2) {
  35.         List<String> result = SKITH1.commonElements(list1, list2);
  36.         assertTrue(result == null || result.size() > 0);
  37.     }
  38.  
  39.     @ParameterizedTest
  40.     @MethodSource("generateTest5Data")
  41.     void test5(List<String> list1, List<String> list2) {
  42.         assertThrows(NullPointerException.class, () -> SKITH1.commonElements(list1, list2));
  43.     }
  44.  
  45.  
  46.     static Stream<Arguments> generateTest1Data() {
  47.         return Stream.of(
  48.                 Arguments.of(Arrays.asList("a", "b", "c"), Arrays.asList("d", "e", "f")),
  49.                 Arguments.of(Arrays.asList("g", "h", "i"), Arrays.asList("j", "k", "l"))
  50.         );
  51.     }
  52.  
  53.     static Stream<Arguments> generateTest2Data() {
  54.         return Stream.of(
  55.                 Arguments.of(Arrays.asList("a", "b", "c"), List.of()),
  56.                 Arguments.of(Arrays.asList("a", "b", "c"), List.of()),
  57.                 Arguments.of(Arrays.asList("a", "b", "c"), List.of())
  58.         );
  59.     }
  60.  
  61.     static Stream<Arguments> generateTest3Data() {
  62.         return Stream.of(
  63.                 Arguments.of(Arrays.asList("a", "b", "c"), null),
  64.                 Arguments.of(Arrays.asList("a", "b", "c"), null),
  65.                 Arguments.of(Arrays.asList("a", "b", "c"), null)
  66.         );
  67.     }
  68.  
  69.     static Stream<Arguments> generateTest4Data() {
  70.         return Stream.of(
  71.                 Arguments.of(List.of(), Arrays.asList("a", "b", "c")),
  72.                 Arguments.of(List.of(), Arrays.asList("a", "b", "c"))
  73.         );
  74.     }
  75.  
  76.     static Stream<Arguments> generateTest5Data() {
  77.         return Stream.of(
  78.                 Arguments.of(null, Arrays.asList("a", "b", "c")),
  79.                 Arguments.of(null, Arrays.asList("a", "b", "c"))
  80.         );
  81.     }
  82.  
  83.     // Functionality-based tests
  84.     @ParameterizedTest
  85.     @MethodSource("generateTest6Data")
  86.     void test6(List<String> list1, List<String> list2) {
  87.         List<String> result = SKITH1.commonElements(list1, list2);
  88.         assertTrue(result.size() > 1);
  89.     }
  90.  
  91.     @ParameterizedTest
  92.     @MethodSource("generateTest7Data")
  93.     void test7(List<String> list1, List<String> list2) {
  94.         List<String> result = SKITH1.commonElements(list1, list2);
  95.         assertTrue(result.size() == 1);
  96.     }
  97.  
  98.     @ParameterizedTest
  99.     @MethodSource("generateTest8Data")
  100.     void test8(List<String> list1, List<String> list2) {
  101.         assertNull(SKITH1.commonElements(list1, list2));
  102.     }
  103.  
  104.  
  105.     static Stream<Arguments> generateTest6Data() {
  106.         return Stream.of(
  107.                 Arguments.of(Arrays.asList("a", "b", "c"), Arrays.asList("a", "b", "c")),
  108.                 Arguments.of(Arrays.asList("a", "b", "c"), Arrays.asList("a", "b", "c"))
  109.         );
  110.     }
  111.  
  112.     static Stream<Arguments> generateTest7Data() {
  113.         return Stream.of(
  114.                 Arguments.of(Arrays.asList("a", "b", "c"), Arrays.asList("a", "d", "f")),
  115.                 Arguments.of(Arrays.asList("a", "b", "c"), Arrays.asList("a", "d", "f"))
  116.         );
  117.     }
  118.  
  119.     static Stream<Arguments> generateTest8Data() {
  120.         return Stream.of(
  121.                 Arguments.of(Arrays.asList("a", "b", "c"), Arrays.asList("z", "d", "f")),
  122.                 Arguments.of(Arrays.asList("a", "b", "c"), Arrays.asList("z", "d", "f"))
  123.         );
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement