简体   繁体   English

使用 IntelliJ 运行 JUnit 测试

[英]Run JUnit test with IntelliJ

I'm using IntelliJ 2018.1 and I am trying to run a TeaVM JUnit test but when running the test from CTRL + SHIFT + F10 tests are getting skipped:我正在使用 IntelliJ 2018.1 并且我正在尝试运行TeaVM JUnit 测试,但是当从CTRL + SHIFT + F10运行测试时,测试被跳过:

@RunWith(TeaVMTestRunner.class)
@SkipJVM
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ShapeTest {

    static final Logger logger = Logger.getLogger(ShapeTest.class.getName());
    @Rule
    public final ExpectedException exception = ExpectedException.none();

    @Test
    public void testGet() {
        System.out.println("ShapeTest - testGet");
        String response = Shape.get("https://httpbin.org/get")
                .header("accept", "application/json")
                .header("Content-Type", "application/json")
                .asJson();

        JSONObject json = new JSONObject(response);
        String url = json.getString("url");
        JSONObject headers = json.getJSONObject("headers");
        assertNotNull(json);
        assertNotNull(url);
        assertNotNull(headers);

        System.out.println(json.toString());
    }

}

But when running from terminal using this command below, it works:但是当使用下面的这个命令从终端运行时,它可以工作:

mvn test -Dteavm.junit.target=target/js-tests -Dteavm.junit.js.runner=h
tmlunit -Dteavm.junit.js.threads=2

Any IntelliJ/JUnit expert here that may have some idea why is this happening?这里的任何 IntelliJ/JUnit 专家可能知道为什么会发生这种情况?

You can specify the same -D parameters in Run configuration settings.您可以在运行配置设置中指定相同的-D参数。 Press "Run" (Alt+Shift+F10 on Windows, Ctrl+Alt+R on Mac), select your run configuration, Right arrow, Edit:按“运行”(Windows 上为 Alt+Shift+F10,Mac 上为 Ctrl+Alt+R),选择您的运行配置,向右箭头,编辑:

编辑配置

Then specify all -D parameters under VM options:然后在 VM 选项下指定所有-D参数:

虚拟机选项

After that, the options will be passed to TeaVM Runner just like it works with mvn test command.之后,这些选项将传递给 TeaVM Runner,就像它与mvn test命令一起工作一样。

If you are new to intellij as I m.如果您像我一样不熟悉 intellij。 I had junits written, only wanted to run them.我写了 junits,只想运行它们。 In eclipse, you go to test class-> right click -> run-> as junit .在 eclipse 中,你去 test class-> right click -> run-> as junit Somewhat like this we do.有点像我们这样做。 Its similar in intellij too.它在intellij中也很相似。 Go to test class right click and run as junits.转到测试类,右键单击并作为 junit 运行。 If such option is not available, then the problem might lie at file->project structure-> module-> source here your tests must not been configured to the test folder of your repo.如果这样的选项不可用,那么问题可能出在文件->项目结构->模块->源这里你的测试不能被配置到你的repo的测试文件夹中。 So, in project structure-> module->sources click on test in module and then select the path to test folder .因此,在项目结构-> 模块-> 源中单击模块中的测试,然后选择测试文件夹的路径。 Then apply-> ok.然后申请-> 好的。 Now Run as test option will be available on right click on test class.现在运行作为测试选项将在右键单击测试类时可用。

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

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