How To Write A JUnit Test Method

  • 20 Jan, 2012

    This interview question is to check if you know the basic rules about writing a JUnit test method: * You need to mark the method as a JUnit test method with the JUnit annotation: @org.junit.Test. * A JUnit test method must be a "public" method. This allows the runner class to access this method. * A JUnit test method must be a "void" method. The runner class does not check any return values. * A JUnit test should perform one JUnit assertion - calling an org.junit.Assert.assertXXX() method.Here is a simple JUnit test method:import org.junit.*; ... @Test public void testHello() { String message = "Hello World!"; Assert.assertEquals(12, message.length()); }

    Comments Received:
    Please give your suggestions and feedback:

2009-2016 All rights reserved.