Skip to content

Run test in Code lens in junit test with wrong home location #458

Closed

Description

@IMEVER

In junit test class, when I click Run test in Code lens, the current run path goes to HOME dir, not current workspace dir.
Run mvn test is correct.

Here is my test class:

`

public class ReportModelTest {
@BeforeClass
public static void before() {
PropertyConfigurator.configure("conf/log4j.conf");
DbUtil.initMysql("conf/mysql.conf");
}

@Test
public void tt() {
    System.out.println(new File("./").getAbsolutePath());
    System.out.println("Test");
}

@Ignore
public void sum() {
    ReportModel.getModel().calculate("2018-11-21");
}

}

`

Part of my log info:
`
[ERROR] at com.microsoft.java.test.runner.Launcher.main(Launcher.java:53)
.
[ERROR] log4j:ERROR Ignoring configuration file [conf/log4j.conf].
.
[INFO] @@<TestRunner-{"name":"testSuiteStarted", "attributes":{"name":"com.adsame.model.mysql.ReportModelTest"}}-TestRunner>
[INFO] @@<TestRunner-{"name":"testStarted", "attributes":{"name":"com.adsame.model.mysql.ReportModelTest#tt"}}-TestRunner>
[INFO] /home/rhett/.
Test
[INFO] @@<TestRunner-{"name":"testFinished", "attributes":{"name":"com.adsame.model.mysql.ReportModelTest#tt", "duration":"1"}}-TestRunner>
[INFO] @@<TestRunner-{"name":"testSuiteFinished", "attributes":{"name":"com.adsame.model.mysql.ReportModelTest"}}-TestRunner>
[INFO] @@<TestRunner-{"name":"testSummary", "attributes":{"message":"Total tests run: 1, Failures: 0, Skips: 0"}}-TestRunner>

`

Activity

  1. IMEVER commented on Nov 26, 2018

    @IMEVER
    Author

    My vscode-java-test version: 0.11.0

  2. jdneo commented on Dec 3, 2018

    @jdneo
    Member

    林业天 (@IMEVER)

    Try to edit launch.test.json as following:

    {
        "run": {
            "default": "<your configuration name>",
            "items": [
                {
                    "name": "<your configuration name>",
                    "projectName": "<your project name>",
                    "workingDirectory": "<the working dir>",
                    "args": [],
                    "vmargs": [],
                    "env": {},
                    "preLaunchTask": ""
                }
            ]
        },
        "debug": {
            "default": "<your configuration name>",
            "items": [
                {
                    "name": "<your configuration name>",
                    "projectName": "<your project name>",
                    "workingDirectory": "<the working dir>",
                    "args": [],
                    "vmargs": [],
                    "env": {},
                    "preLaunchTask": ""
                }
            ]
        }
    }

    Then set the value of default to the name of the configuration item you want to use.

    Let me know if this could help with your problem.

  3. IMEVER commented on Dec 4, 2018

    @IMEVER
    Author

    Sheng Chen (@jdneo) Yes, it works. You save my life.
    By the way, I have three probjects in the current vscode workspace, can it just automaticly pick the right configuration file when run in test class. Now I have to run test method from left side test pannel with right click and choose configration file.
    Below is my config:

    {
        "run": {
            "default": "MobileTracker-Report",
            "items": [
                {
                    "name": "MobileTrackerServer",
                    "projectName": "MobileTrackerServer",
                    "workingDirectory": "/data/code/java/TransferParameter/MobileTrackerServer",
                    "args": [],
                    "vmargs": [],
                    "env": {},
                    "preLaunchTask": ""
                },
                {
                    "name": "MobileTrackerReport",
                    "projectName": "MobileTrackerReport",
                    "workingDirectory": "/data/code/java/TransferParameter/MobileTrackerReport",
                    "args": [],
                    "vmargs": [],
                    "env": {},
                    "preLaunchTask": ""
                },
                {
                    "name": "MobileTracker-Report",
                    "projectName": "MobileTracker-Report",
                    "workingDirectory": "/data/code/java/TransferParameter/MobileTracker-Report",
                    "args": [],
                    "vmargs": [],
                    "env": {},
                    "preLaunchTask": ""                
                }
            ]
        }
    }
    
  4. IMEVER commented on Dec 4, 2018

    @IMEVER
    Author

    Sheng Chen (@jdneo) Now I have to use absolute path in launch.test.json, Hope launch.test.json will support variable like "${workspaceFolder}" in launch.json.

  5. jdneo commented on Dec 4, 2018

    @jdneo
    Member

    林业天 (@IMEVER) Glad to know problems are resolved.

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