code_junkie

Best Practice: Initialize JUnit class fields in setUp() or at declaration

Nov 14th, 2011
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. public class SomeTest extends TestCase
  2. {
  3. private final List list = new ArrayList();
  4.  
  5. public void testPopulateList()
  6. {
  7. // Add stuff to the list
  8. // Assert the list contains what I expect
  9. }
  10. }
  11.  
  12. public class SomeTest extends TestCase
  13. {
  14. private List list;
  15.  
  16. @Override
  17. protected void setUp() throws Exception
  18. {
  19. super.setUp();
  20. this.list = new ArrayList();
  21. }
  22.  
  23. public void testPopulateList()
  24. {
  25. // Add stuff to the list
  26. // Assert the list contains what I expect
  27. }
  28. }
Add Comment
Please, Sign In to add comment