Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. import org.junit.BeforeClass;
  2. import org.junit.Test;
  3. import org.junit.Assert;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.test.context.ContextConfiguration;
  6. import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
  7.  
  8. @ContextConfiguration(locations = { "classpath:test-config.xml" })
  9. public class TestNothing extends AbstractJUnit4SpringContextTests {
  10.  
  11. @Autowired
  12. PersonRepository repo;
  13.  
  14. @BeforeClass
  15. public static void runBefore() {
  16. System.out.println("@BeforeClass: set up.");
  17. }
  18.  
  19. @Test
  20. public void testInit() {
  21. Assert.assertTrue(repo.findAll().size() == 0 );
  22. }
  23. }
  24.  
  25. => @BeforeClass: set up.
  26. => Process finished with exit code 0
  27.  
  28. import org.springframework.test.context.TestContext;
  29. import org.springframework.test.context.support.AbstractTestExecutionListener;
  30.  
  31. public class BeforeClassHook extends AbstractTestExecutionListener {
  32.  
  33. public BeforeClassHook() { }
  34.  
  35. @Override
  36. public void beforeTestClass(TestContext testContext) {
  37. System.out.println("BeforeClassHook.beforeTestClass(): set up.");
  38. }
  39. }
  40.  
  41. import org.springframework.test.context.TestExecutionListeners;
  42. // other imports are the same
  43.  
  44. @ContextConfiguration(locations = { "classpath:test-config.xml" })
  45. @TestExecutionListeners(BeforeClassHook.class)
  46. public class TestNothing extends AbstractJUnit4SpringContextTests {
  47.  
  48. @Autowired
  49. PersonRepository repo;
  50.  
  51. @Test
  52. public void testInit() {
  53. Assert.assertTrue(repo.findAll().size() == 0 );
  54. }
  55. }
  56.  
  57. => BeforeClassHook.beforeTestClass(): set up.
  58. => Process finished with exit code 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement