还是比较喜欢单独jar包的形式,自己编译又总是不成功。junit4与junit5语法不完全兼容。
用户手册中提到,有个适合在命令行执行的jar包 https://junit.org/junit5/docs/current/user-guide/#running-tests-console-launcher。
这是仓库https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone/
最简单例子
1 // filename: Calculator.java 2 public class Calculator{ 3 public static int add(int a,int b){ 4 return a+b; 5 } 6 }
1 // filename: MyFirstJUnitJupiterTests.java 2 3 import static org.junit.jupiter.api.Assertions.assertEquals; 4 5 //import Calculator; 6 7 import org.junit.jupiter.api.Test; 8 9 class MyFirstJUnitJupiterTests { 10 11 private final Calculator calculator = new Calculator(); 12 13 @Test 14 void addition() { 15 assertEquals(2, calculator.add(1, 1)); 16 } 17 18 }
编译:
javac -cp junit-platform-console-standalone-1.9.2.jar MyFirstJUnitJupiterTests.java Calculator.java
运行
java -jar junit-platform-console-standalone-1.9.2.jar -f MyFirstJUnitJupiterTests
ref:
https://blog.csdn.net/c13232906050/article/details/93756357
https://junit.org/junit5/docs/current/user-guide/#running-tests-console-launcher
标签:console,命令行,Calculator,jar,测试,org,junit5,junit From: https://www.cnblogs.com/weixicai/p/17189140.html