关于 System.getProperty("eclipse.commands") 的信息以断言 JUnits 测试是否 运行 作为 JUnit 插件

Information about System.getProperty("eclipse.commands") to assert if JUnits tests are being run as a plug-in JUnit

我的 JUnit 测试 class ValidateConfig.java 中有一个函数断言测试是否 运行 作为插件JUnit(函数已在下面提到),如果不是,则抛出 IllegatStateException。我想知道这是如何工作的,getProperty 方法调用中的参数是什么意思?我尝试研究但找不到满意的答案请告诉我您的建议。

private void validate() {
if (System.getProperty("eclipse.commands") == null) {
throw new IllegalStateException("Test must be run as a Plug-in JUnit.");
}
}

您可以列出所有当前系统属性并查看详细信息:

public class Test {
    public static void main(String[] a) {
        Properties p = System.getProperties();
        p.list(System.out);
    }
}

您可以在程序 System.setProperty("eclipse.commands", "test"); 或 JVM 参数 -Dkey=value.

中设置属性

这只是一个系统属性,保证在启动期间由 Eclipse 设置,不太可能在非 运行 Eclipse 的 JVM 中设置。

runtime options help 详细介绍了 Eclipse 设置的属性。