Skip to content

how to specify a system environment for junit test in vscode #354

Closed

Description

@yong9900

My junit test only runs successfully when a system environment is setup.

I looked into <project_dir>/.vscode/launch.test.json, there is env json property, I put something like this:

"env": { "MY_ENV": "env_value"},

but in my test, MY_ENV is not setup.

Is this a bug or this is not supported?

Activity

  1. jdneo commented on Oct 26, 2018

    @jdneo
    Member

    yong9900

    If you right click the tests you want to trigger in the test explorer and select test Run With Config. Will this work for you?

  2. yong9900 commented on Oct 26, 2018

    @yong9900
    Author

    unfortunately, it does not work.
    I have following in my launch.test.json:
    "debug": { "default": "", "items": [ { "name": "integration-tests", "projectName": "integration-tests", "workingDirectory": "<some dir>", "args": [], "vmargs": [], "env": { "MYENV": "why abc" }, "preLaunchTask": "" } ] }

    With this, when I evaluate following in the code:
    final String configPath= System.getenv( "MYENV" );
    I got nothing.

  3. yong9900 commented on Oct 26, 2018

    @yong9900
    Author

    I actually did a thorough test. realized several things:

    1. The env property in launch.test.json never gets picked up in the test, regardless use getenv() or getProperty().
    2. There is no doc describe about launch.test.json, so I am not sure if it is really used by java tester extension.
    3. Looks like junit test does pick up workingDirectory definition in launch.test.json.

    At this point, I suspect there is a bug in the java tester extension that does not honor env property in launch.test.json

  4. chuckb commented on Nov 1, 2018

    @chuckb

    Works for me so long as the configuration is run, by either explicitly picking it from the test explorer OR setting the default parameter to the name of the configuration you want to be the default.

  5. jdneo commented on Nov 9, 2018

    @jdneo
    Member

    yong9900 Would you mind sharing a sample project which can repro your issue?

  6. yong9900 commented on Nov 9, 2018

    @yong9900
    Author

    Sheng Chen (@jdneo) Hi Sure. I will try to put a simple project on github shortly. At the same time, I just tried, didn't work for me. will send out the project once I setup.

  7. yong9900 commented on Nov 10, 2018

    @yong9900
    Author

    Sheng Chen (@jdneo) Hi I tried again, this time, I can't reproduce the problem. I think my problem could related to my uncleaned workplace cache. will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions