Wednesday, October 28, 2009

JUnit4 public setup method in Eclipse

I converted a JUnit test case from JUnit3 to JUnit4 style. This mostly involves not extending TestCase and using annotations such as @Test and @Before etc. JUnit4 in 60 Seconds is an excellent tutorial.

I ran into a problem, however. A test method did not run after the conversion. Eclipse did not throw any error. Its JUnit View simply said "finished in 0 seconds", like it did not run it at all. Eventually I found that the setUp() method was still "protected" as in JUnit3. Everything worked after I changed it to "public".

    /**
* Setup.
*/
@Before
public void setUp() {
// ...
}



Nowhere said that the setup method must be public. It might be an Eclipse thing. Anyway, I just want to note it down here and will revisit it later.

1 comment:

  1. My first post after finding out how to format source code by
    http://formatmysourcecode.blogspot.com/

    Bye messy, welcome pretty!

    ReplyDelete