JUnit5 test classes and methods should have default package visibility

This commit is contained in:
Alex Golub 2022-04-22 21:21:20 +03:00
parent 4bcb36ff41
commit da30a3efd7
5 changed files with 31 additions and 29 deletions

View File

@ -1,28 +1,29 @@
package com.baeldung.junit5.order; package com.baeldung.junit5.order;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.TestMethodOrder;
import static org.junit.Assert.assertEquals;
@TestMethodOrder(MethodOrderer.MethodName.class) @TestMethodOrder(MethodOrderer.MethodName.class)
public class AlphanumericOrderUnitTest { public class AlphanumericOrderUnitTest {
private static StringBuilder output = new StringBuilder(""); private static StringBuilder output = new StringBuilder("");
@Test @Test
public void myATest() { void myATest() {
output.append("A"); output.append("A");
} }
@Test @Test
public void myBTest() { void myBTest() {
output.append("B"); output.append("B");
} }
@Test @Test
public void myaTest() { void myaTest() {
output.append("a"); output.append("a");
} }

View File

@ -8,24 +8,25 @@ import org.junit.jupiter.api.TestMethodOrder;
@TestMethodOrder(CustomOrder.class) @TestMethodOrder(CustomOrder.class)
public class CustomOrderUnitTest { public class CustomOrderUnitTest {
private static StringBuilder output = new StringBuilder(""); private static StringBuilder output = new StringBuilder("");
@Test @Test
public void myATest() { void myATest() {
output.append("A"); output.append("A");
} }
@Test @Test
public void myBTest() { void myBTest() {
output.append("B"); output.append("B");
} }
@Test @Test
public void myaTest() { void myaTest() {
output.append("a"); output.append("a");
} }
@AfterAll @AfterAll
public static void assertOutput() { public static void assertOutput() {
assertEquals(output.toString(), "AaB"); assertEquals(output.toString(), "AaB");

View File

@ -12,19 +12,19 @@ public class DefaultOrderUnitTest {
@Test @Test
@DisplayName("Test A") @DisplayName("Test A")
public void myATest() { void myATest() {
output.append("A"); output.append("A");
} }
@Test @Test
@DisplayName("Test B") @DisplayName("Test B")
public void myBTest() { void myBTest() {
output.append("B"); output.append("B");
} }
@Test @Test
@DisplayName("Test C") @DisplayName("Test C")
public void myCTest() { void myCTest() {
output.append("C"); output.append("C");
} }

View File

@ -11,25 +11,25 @@ import org.junit.jupiter.api.TestMethodOrder;
@TestMethodOrder(OrderAnnotation.class) @TestMethodOrder(OrderAnnotation.class)
public class OrderAnnotationUnitTest { public class OrderAnnotationUnitTest {
private static StringBuilder output = new StringBuilder(""); private static StringBuilder output = new StringBuilder("");
@Test @Test
@Order(1) @Order(1)
public void firstTest() { void firstTest() {
output.append("a"); output.append("a");
} }
@Test @Test
@Order(2) @Order(2)
public void secondTest() { void secondTest() {
output.append("b"); output.append("b");
} }
@Test @Test
@Order(3) @Order(3)
public void thirdTest() { void thirdTest() {
output.append("c"); output.append("c");
} }
@AfterAll @AfterAll
public static void assertOutput() { public static void assertOutput() {
assertEquals(output.toString(), "abc"); assertEquals(output.toString(), "abc");

View File

@ -13,17 +13,17 @@ public class RandomOrderUnitTest {
private static StringBuilder output = new StringBuilder(""); private static StringBuilder output = new StringBuilder("");
@Test @Test
public void myATest() { void myATest() {
output.append("A"); output.append("A");
} }
@Test @Test
public void myBTest() { void myBTest() {
output.append("B"); output.append("B");
} }
@Test @Test
public void myCTest() { void myCTest() {
output.append("C"); output.append("C");
} }