简体   繁体   English

在 Sublime Text 3 中构建文件以调用 JUnit5 测试

[英]Build file in Sublime Text 3 to invoke JUnit5 tests

I am trying to configure Sublime Text 3 's RunJava.sublime-build file to add an option to execute JUnit 5 test on Mac OS X .我正在尝试配置Sublime Text 3RunJava.sublime-build文件以添加一个选项以在Mac OS X上执行JUnit 5测试。

The following works for me from the Mac OS X terminal window:以下内容适用于 Mac OS X 终端 window:

$ java -jar /Users/pavlomaistrenko/Documents/Junit1.6/junit-platform-console-standalone-1.6.2.jar -cp /Users/pavlomaistrenko/Documents/GitHub/SvitlanaMo/Java01/ --scan-classpath

My RunJava.sublime-build configuration file is:我的RunJava.sublime-build配置文件是:

{
    "selector": "source.java",
    "file_patterns": "*.java",
    "working_dir": "$file_path",
    "shell_cmd": "javac -cp .:/Users/pavlomaistrenko/Documents/GitHub/SvitlanaMo/Java01/:/Users/pavlomaistrenko/Documents/Junit1.6/junit-platform-console-standalone-1.6.2.jar $file_name",
    "variants": [
        {
            "name": "Run class.jar",
            "shell_cmd": "java -cp .:/Users/pavlomaistrenko/Documents/GitHub/SvitlanaMo/Java01/:/Users/pavlomaistrenko/Documents/Junit1.6/junit-platform-console-standalone-1.6.2.jar $file_base_name"
        },

        {
            "name": "JavaDoc",
            "shell_cmd": "mkdir -p documentation && javadoc -header \"<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>\" -d documentation *.java"
        },

        {
            "name": "JAR",
            "cmd": "javac '$realpath$file' && echo \"Main-Class: $file_base_name\" > Manifest.txt && jar cfm $file_base_name.jar Manifest.txt *.class && rm *.class && java -jar $file_base_name.jar"
        },

        {
            "name": "JUnit5",
            "cmd": "java -jar /Users/pavlomaistrenko/Documents/Junit1.6/junit-platform-console-standalone-1.6.2.jar -cp $file_path --scan-classpath"
        }

    ]
}

Instead of full JUnit 5 output I just get [Finished in X.Xs] .而不是完整的 JUnit 5 output 我只是得到[Finished in X.Xs]

Does JUnit get executed? JUnit 是否被执行? If so, where is the output?如果是这样,output 在哪里?

PS I have read Sublime is not a perfect environment for Java, but still. PS 我读过 Sublime 不是 Java 的完美环境,但仍然如此。

I suspect what you are doing to trigger the unit tests is either using the B keyboard shortcut or selecting Tools → Build from the menu.我怀疑您触发单元测试的操作是使用 B键盘快捷键或从菜单中选择Tools → Build The way Sublime's build systems work, this will only trigger the initial "shell_cmd" command. Sublime 构建系统的工作方式,这只会触发初始的"shell_cmd"命令。 The way to run one of the variants is to use B or select Tools → Build With… .运行其中一种变体的方法是使用 B或 select Tools → Build With… This will display a dropdown with all the different variants available.这将显示一个下拉列表,其中包含所有可用的不同变体。 Selecting JUnit5 should run your unit tests as specified.选择JUnit5应该按照指定运行您的单元测试。

Finally found out a working build configuration for JUnit5.终于找到了 JUnit5 的有效构建配置。 Here is the snippet:这是片段:

{
    "name": "JUnit5 the folder",
    "env": { "user_path": "/Users/pavlomaistrenko/Documents",
     "junit5":  "Junit1.6/junit-platform-console-standalone-1.6.2.jar",
     "project_path": "GitHub/SvitlanaMo/Java01/"
   },
    "shell_cmd": "java -jar \\$user_path/\\$junit5 -cp .:$file_path --scan-classpath"
},

Note the double escaping of $ with two backslashes \\ for Mac OS.请注意$的双 escaping 和 Mac OS 的两个反斜杠\\ The env variables are not expanded by Sublime, rather they are set as environment variables for this particular call of java loader (and then expanded by the shell.) See Use custom variables in Sublime Text build system for explanation. Sublime 不会扩展环境变量,而是将它们设置为java加载程序的特定调用的环境变量(然后由 shell 扩展。)请参阅在 Sublime Text 构建系统中使用自定义变量以获取解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM