Interview Questions

How to Run Your JUnit 4.4 Tests with a JUnit 3.8 Runner?

JUnit Questions and Answers


(Continued from previous question...)

How to Run Your JUnit 4.4 Tests with a JUnit 3.8 Runner?

I am not sure why you have to do this. But if you want to, you can use the junit.framework.JUnit4TestAdapter class included in JUnit 4.4 JAR file. Here is sample code:

import junit.framework.Test;
import junit.textui.TestRunner;
import junit.framework.JUnit4TestAdapter;
// by FYICenter.com

public class JUnit3Adapter {
  public static void main (String[] args) {
    Test adaptedTest = new JUnit4TestAdapter(HelloTest.class);
    TestRunner.run(adaptedTest);
  }
}

Classes junit.framework.Test, junit.textui.TestRunner and junit.framework.JUnit4TestAdapter are included in the JUnit 4.4 JAR file. You don't need to include the JUnit 3.8 JAR file in your CLASSPATH.

(Continued on next question...)

Other Interview Questions