Reputation: 684
I'm running the demo in:
https://github.com/junit-team/junit4/wiki/Getting-started
I copied Calculator and CalculatorTest exactly as displayed in the page. Compiling failed though:
D:\workspace\junit-example>java -cp d:\junit\latest\junit.jar;. CalculatorTest
Error: Main method not found in class CalculatorTest, please define the main method as:
public static void main(String[] args)
So I created this file:
public class Runner {
public Runner() {
}
public static void main(String[] args) {
CalculatorTest c = new CalculatorTest();
c.evaluatesExpression();
}
}
The problem is, even though everything compiles and runs (see output below), there isn't any output from JUnit. What is needed to see the result of the test?
D:\workspace\junit-example>javac -cp d:\junit\latest\junit.jar;. *.java
D:\workspace\junit-example>java -cp d:\junit\latest\junit.jar;. Runner
D:\workspace\junit-example>
Upvotes: 0
Views: 338
Reputation: 124
You don't need your Runner
class. Instead, when you run your program, specify org.junit.runner.JUnitCore
as the class to run, not CalculatorTest
. That way, JUnit will run the test. It's mentioned further down on the page you linked to, under "Run the test."
java -cp .;junit-4.XX.jar;hamcrest-core-1.3.jar org.junit.runner.JUnitCore CalculatorTest
Upvotes: 1
Reputation: 8758
You are running it in a wrong way.
You do not need Runner
class at all. Also you need to run jUnit runner class and pass class with test methods as a parameter. This is mentioned in that tutorial:
java -cp .;junit-4.XX.jar;hamcrest-core-1.3.jar org.junit.runner.JUnitCore CalculatorTest
Upvotes: 2