View RSS Feed

Recent Blogs Posts

  1. Sharing setUp() and tearDown() code for all tests - I

    by , 05-21-2011 at 11:29 PM (My Java Tips)
    You may wish to share the code written in setUp() and tearDown() methods of your JUnit tests. This clearly will indicate that you have excessive coupling in your design. Coupling is not bad always but if more tests share the same test fixture state, then this indicates that the classes under test have some undesirable dependencies.

    You may wish to remove these dependencies but its another stories. As I said, coupling or dependencies are not always bad. But if you wish to keep coupling ...
    Tags: setup, teardown Add / Edit Tags
    Categories
    JUnit
  2. Sharing setUp() and tearDown() code for all tests - II

    by , 05-21-2011 at 11:28 PM (My Java Tips)
    This post presents an example that shows how to use @BeforeClass and @AfterClass annotation.

    Java Code:
        public class SimpleTest {
        
            private Collection collection;
    	
            @BeforeClass
            public static void oneTimeSetUp() {
                // one-time initialization code        
            }
    
            @AfterClass
            public static void oneTimeTearDown() {
                // one-time cleanup code
    ...
    Tags: setup, teardown Add / Edit Tags
    Categories
    JUnit