vscode-java-test icon indicating copy to clipboard operation
vscode-java-test copied to clipboard

Support run TestNG suites toward XML file

Open jdneo opened this issue 6 years ago • 31 comments
trafficstars

The experience could be adding a command action into the file explorer context menu, like this:

image

jdneo avatar Jan 28 '19 01:01 jdneo

Thanks, It would be a great feature that will help in debugging for automation testing frameworks written in Java. Are we getting this soon or not ?

Mohannad91 avatar Mar 31 '19 22:03 Mohannad91

Hi @Mohannad91,

Do you mean in the context menu, you want another item called Debug Test?

jdneo avatar Apr 01 '19 01:04 jdneo

Hi @jdneo .. yeah exactly what i meant.. it's a popular and important feature for automation engineers using java and TestNG to build their framework.. it'll make life way easier

Mohannad91 avatar Apr 09 '19 18:04 Mohannad91

@jdneo: While the "Run Test" context menu command would be handy, users can get equivalent functionality by right clicking a Maven project and choosing the test goal. To expand on the comments above, one thing that the VSCode extension can't do right now is run or debug at the class and method level using info specified in testng.xml.

Example: With TestNG, I can use the @Parameters decorator to specify that I'd like TestMethod1() to use a parameter called "username". Then, I can specify a value for "username" in a testng.xml file specified in the Maven project's pom.xml. I can also specify in the testng.xml file that I'd like to only run the TestMethod1() method next build. From there, I could run mvn test from the Terminal, only TestMethod1() would fire, TestNG would notice that I have a parameter called "username" specified for it in testng.xml, and that parameter would be plugged into my test method.

However, using the CodeLens "Run Test" or "Debug Test" action on TestMethod1() will result in a Skip by TestNG - by clicking on those, I'm running the class, not the whole project, so CodeLens doesn't know what "username" is. It does know that it's a @Parameter that's not specified in any file it knows about, so TestNG returns an error. Now, imagine this project has dozens or hundreds of test methods; running the whole project just to check one method is cumbersome, and editing my testng.xml each time I want to just run or debug one method is tedious.

A nice feature would be to automagically give Run Test and Debug Test visibility to the stuff specified in testng.xml. @Parameters would be one such example that's fairly straightforward. Getting more stuff out of testng.xml at runtime might be nontrivial and something you might consider splitting into subtasks.

dg-ceiland avatar Apr 16 '19 00:04 dg-ceiland

Hi @dg-ceiland,

Sorry for my late reply and thank you for the detailed explanation. Just as you have said, the extension currently has limited support on TestNG. And your suggestion is very inspiring.

I think I can first support running/debugging towards the testng.xml and then make the codelens(Run Test/Debug Test) more intelligent.

jdneo avatar May 23 '19 02:05 jdneo

Hi @all,

Now have one problem with this issue. The VS Code when API can only check the file name but has no ability to check the content. This limitation may introduce some problems here:

  • Add Run/Debug Test menu item for all *.xml file: This implementation can make sure that we won't miss any TestNG XML files in the project. But it will be confusing when the user right clicks on other XML files, like pom.xml.
  • Add Run/Debug Test menu item for all the XML files whose file name contains testng. By doing this, we limited the entry points but we may also miss some of the configuration files.

I prefer the first one, but I'm worrying about the confusion that may be introduced here. Do you guys have any thoughts on this?

jdneo avatar May 28 '19 05:05 jdneo

@jdneo Just to confirm we're talking about the same thing (I don't believe we are), I've included a screenshot of the Run / Debug Test UI clickables that I'm thinking of.

image

Perhaps my suggestion is outside of the scope of this issue. In any case, it's tricky to say which of your options is better - option 1 would probably be my choice as well.

dg-ceiland avatar May 28 '19 17:05 dg-ceiland

@dg-ceiland I think you are talking about bringing the context defined in testng.xml to the Run Test & Debug Test actions. Am I right?

jdneo avatar May 29 '19 02:05 jdneo

@jdneo Yes. Is this within scope, or even doable? If so, is this something that should be put into a different issue?

dg-ceiland avatar May 29 '19 16:05 dg-ceiland

@dg-ceiland Yes, I think it would be better to file this into another new issue.

Would you mind to file a new issue for that?

jdneo avatar May 30 '19 00:05 jdneo

@jdneo Any updates on this? Would really want the ability to run testng tests from xmls, just by right clicking and "Run Test"/"Debug Test". Often have many tests in the xmls that run parallel. As it is done in Eclipse today.

oliversundell avatar Oct 18 '19 11:10 oliversundell

@oliversundell,

There is one concern that so far I cannot find a way to figure out testng specific xml. If I simply add the test/debug menu item to all xml files, this would be a little bit annoying.

jdneo avatar Oct 25 '19 07:10 jdneo

@jdneo Yeah, understand. Is there any way to customize the context menu my self to achieve this (I can accept that I get the options on all xmls)?

oliversundell avatar Oct 25 '19 13:10 oliversundell

@oliversundell Your comment inspired me! So actually there is some ways to filter the unexpected run/debug menu items, for example:

  • When only the extension detects there is TestNG in class path, we show them
  • Or we can provide an extension setting to let the users specify whether they want to have them show in the context menu for the .xml files.

jdneo avatar Oct 28 '19 01:10 jdneo

@jdneo Great! Think both options sounds good. I'm just eager to loose Eclipse and move my development of testng to vs :)

oliversundell avatar Oct 28 '19 09:10 oliversundell

@jdneo - Is there any update on this thread. And can't you implement the same logic how eclipse and intellij idea is doing to run the testng.xml file?

KrishnaSakinala avatar Sep 14 '20 04:09 KrishnaSakinala

Is there any progress on this issue, this feature would help me a lot

CarlPer avatar May 06 '21 06:05 CarlPer

It would be great to have the feature for test engineers to run BDD cucumber tests and a suite of test script execution as well. Please let us know when we can expect this changes :)

USTQE avatar May 28 '21 04:05 USTQE

Any progress on this? Only missing part for me to move away from other IDEs.

jfmenard avatar Oct 28 '21 17:10 jfmenard

Same here. waiting for this to be implemented before i can dump Eclipse

joshzhuang1 avatar Nov 04 '21 04:11 joshzhuang1

Any news about this issue ? or any work around to solve it ?

GerobohamAlvarez avatar Feb 16 '22 19:02 GerobohamAlvarez

Really surprised this is not prioritized more. This is a pretty basic feature & a must-have IMO.

jfmenard avatar Feb 16 '22 19:02 jfmenard

Hello folks, we are taking a look at this issue and evaluating the technical feasibility. Will keep you posted

nickzhums avatar Feb 18 '22 07:02 nickzhums

Any update about this issue?

jfmenard avatar Apr 07 '22 17:04 jfmenard

I don't know how it may be stated that VSCode can support testNG when it cannot kick off by the test xml file.

KipRM avatar Apr 29 '22 14:04 KipRM

Any plan to add this feature. This is only piece which is making me use IntelliJ

abhaybharti avatar May 25 '22 16:05 abhaybharti

"One of the reasons for commercial products can survive is that some popular features cannot be always implemented easily/quickly in FOSS products." -- Somebody

Workarounds to Run TestNG suite file in Vscode:

  • PROJECT/.vscode/launch.json (Run and Debug View to Start)
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Run TestNG Suite",
            "request": "launch",
            "mainClass": "org.testng.TestNG",
            "args": "-d \"testng_output_dir\" -testnames \"test_names\" suite_file_path.xml",
            "vmArgs": "-Dname=value"
        }      
    ]
}
  • .vscode-server/data/Machine/settings.json (Maven Terminal Favorite Command - Maven: Execute Commands... -> Favorite...)
{
    "maven.terminal.favorites": [
        { 
            "alias": "Run TestNG Suite",
            "command": "clean test -Dname=value -Dsurefire.suiteXmlFiles=src/main/resources/suites/path/to/suite_file.xml -f /maven/project/path/pom.xml"
        }    
    ]
}

wenijinew avatar Sep 21 '22 16:09 wenijinew

"One of the reasons for commercial products can survive is that some popular features cannot be always implemented easily/quickly in FOSS products." -- Somebody

Workarounds to Run TestNG suite file in Vscode:

  • PROJECT/.vscode/launch.json (Run and Debug View to Start)
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Run TestNG Suite",
            "request": "launch",
            "mainClass": "org.testng.TestNG",
            "args": "-d \"testng_output_dir\" -testnames \"test_names\" suite_file_path.xml",
            "vmArgs": "-Dname=value"
        }      
    ]
}
  • .vscode-server/data/Machine/settings.json (Maven Terminal Favorite Command - Maven: Execute Commands... -> Favorite...)
{
    "maven.terminal.favorites": [
        { 
            "alias": "Run TestNG Suite",
            "command": "clean test -Dname=value -Dsurefire.suiteXmlFiles=src/main/resources/suites/path/to/suite_file.xml -f /maven/project/path/pom.xml"
        }    
    ]
}

DEV's IDE Use case. The developer, or automation developer may, and likely has any number of testNG xml files available for a test suite. In intellij you can right click these in the left pane files list and run them. Once they are ran they are placed up in a drop down up at the top of the IDE. It is for this reason, anyone using xml based testNG solutions would never use vscode due to a lack of these basic ergonomics.

No one's quote is going to change this.
It challenges the very value of the vsCode TestNG plugin.

KipRM avatar Sep 21 '22 18:09 KipRM

Yes, right click is very good feature. However, in real world, not all the test suites can run simply by simple right click. For our cases, we have to configure tons of dynamical parameters(-Dname=value) or in properties file.

After configuring the TestNG suites, you can also have them in drop-down list: Run and Debug view or Maven Favorites (You can set shortcut for it - I used "Alt + F"). For my feeling, it's not perfect but really good enough to use.

wenijinew avatar Sep 21 '22 20:09 wenijinew

For me, the integration into the UI is not only needed for starting tests, but also to integrate it in the UI with debugging and marked successful and failed tests in the test tree and the code with errors. That is the main benefit that vscode is currently missing on suite xmls compared to eclipse, for example.

benzman81 avatar Sep 21 '22 21:09 benzman81