DemoUnitTest.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package com.ruoyi.test;
  2. import com.ruoyi.common.config.RuoYiConfig;
  3. import org.junit.jupiter.api.*;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.boot.test.context.SpringBootTest;
  6. import java.util.concurrent.TimeUnit;
  7. /**
  8. * 单元测试案例
  9. *
  10. * @author Lion Li
  11. */
  12. @SpringBootTest // 此注解只能在 springboot 主包下使用 需包含 main 方法与 yml 配置文件
  13. @DisplayName("单元测试案例")
  14. public class DemoUnitTest {
  15. @Autowired
  16. private RuoYiConfig ruoYiConfig;
  17. @DisplayName("测试 @SpringBootTest @Test @DisplayName 注解")
  18. @Test
  19. public void testTest() {
  20. System.out.println(ruoYiConfig);
  21. }
  22. @Disabled
  23. @DisplayName("测试 @Disabled 注解")
  24. @Test
  25. public void testDisabled() {
  26. System.out.println(ruoYiConfig);
  27. }
  28. @Timeout(value = 2L, unit = TimeUnit.SECONDS)
  29. @DisplayName("测试 @Timeout 注解")
  30. @Test
  31. public void testTimeout() throws InterruptedException {
  32. Thread.sleep(3000);
  33. System.out.println(ruoYiConfig);
  34. }
  35. @DisplayName("测试 @RepeatedTest 注解")
  36. @RepeatedTest(3)
  37. public void testRepeatedTest() {
  38. System.out.println(666);
  39. }
  40. @BeforeAll
  41. public static void testBeforeAll() {
  42. System.out.println("@BeforeAll ==================");
  43. }
  44. @BeforeEach
  45. public void testBeforeEach() {
  46. System.out.println("@BeforeEach ==================");
  47. }
  48. @AfterEach
  49. public void testAfterEach() {
  50. System.out.println("@AfterEach ==================");
  51. }
  52. @AfterAll
  53. public static void testAfterAll() {
  54. System.out.println("@AfterAll ==================");
  55. }
  56. }