如何在命令行触发的junit测试中添加参数? [英] How to add arguments to junit test triggered from command line?

查看:324
本文介绍了如何在命令行触发的junit测试中添加参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此线程显示了如何使用JUnit测试来测试JAR。但是,我想从命令行提交其他属性(因为我想测试我的main方法)。

This thread here shows how to test a JAR with JUnit tests. However, I want to submit additional properties from the command line (because I want to test my main method).

如何从命令行运行Java的JUnit测试

例如
java -cp /usr/share/java/junit.jar org.junit.runner.JUnitCore [MyTest] [PortNumber] [fileToRead]

e.g. java -cp /usr/share/java/junit.jar org.junit.runner.JUnitCore [MyTest] [PortNumber] [fileToRead]

任何像那可能吗?

推荐答案

你可以使用系统属性

java -cp ... YOUR_TEST -DportNumber=1234

然后在代码中,您可以使用

Then in code, you can retrieve it with

System.getProperty("portNumber")

这篇关于如何在命令行触发的junit测试中添加参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆