-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate xml file of test results as specified in .runsettings file #215
Comments
You are correct. The adapter does not create an XML result file. If we want it to do so, it would help to have some kind of spec. What should be the name, location and content of such a file. How will the user tell nunit to save the results. |
Yet another reason to create a settings UI for the extension 😄 |
Have we talked about such a ui elsewhere? I searched but found nothing. For us to have a ui, we would need to stop being just an adapter and replace at least some of the functionality of the test window. |
I'm not sure if it would work for the nuget package, but a VSIX can add a settings node to the Visual Studio options. |
Right. But then we become an extension in our own right and not an adapter. Or some kind of hybrid. It's not impossible but it is a major escalation. I've thought about doing that as a commercial product. |
Test results that I am looking for could be same as the one generated by console runner but more specifically want numbers like passed, failed, run, time took to run tests. ways that I can think of for doing this –
|
@PriyankaDhamdhere Thanks for the suggestions...
|
Hi, I'm also need this functionality |
@LirazShay User can control which path is used to save output under the console by specifying |
It's not required that the exact path will be determined by the settings. Even if it will be saved in default location - it will help me |
@CharliePoole We're setting the WorkDirectory (https://github.com/nunit/docs/wiki/Tips-And-Tricks ) from runsettings to the engine: Is this the same as the --work parameter to the console? From the notes it says this is just the TestAssembly location, sort of the same as the BinDirectory. Or, does this setting do something else in the engine? Looking more, we ALWAYS set this parameter to the engine, the runsettings just make it possible to change it. So, there must be another setting to generate the output. I know we discussed this earlier, and you mentioned some way to trigger this in the engine. (I have never tried this option) |
@OsirisTerje Yes, that's exactly right. Our The engine has a facility to create the XML output file, but the runner has to call it. It isn't created automatically. You could do something like this... var resultService = _engine.Services.GetService<IResultService>();
// Following null argument should work for nunit3 format. Empty array is OK as well.
// If you decide to handle other formats in the runsettings, it needs more work.
var resultWriter = resultService.GetResultWriter("nunit3", null);
resultWriter.WriteResultFile(yourResult, yourOutputPath); |
Thanks @CharliePoole ! Just what I need! I'll add this in, then at least we have the possibility for an output file implemented. |
@OsirisTerje |
@LirazShay @PriyankaDhamdhere This should now work. There is a pre-release package at https://www.myget.org/feed/nunit/package/nuget/NUnit3TestAdapter/3.12.0-dev-01009 . Would appreciate if you could test it out. I am OOF from Wednesday evening, so if this is going out, it has to be tomorrow. To use it, add the runsettings file, with another NUnit property named TestOutput. That should point to a relative or absolute folder path where you want the output. I'll document the details later. In any case, there is then one result xml file for each test assembly. |
Version 3.12 release, see https://github.com/nunit/docs/wiki/Adapter-Release-Notes, |
@OsirisTerje |
@OsirisTerje |
@LirazShay You seems to have some settings included from the template which is bogus. Can you try with only TestOutput ? |
@LirazShay First, my apologies and thanks for using this - you "found" a bug, documentation and code is not in sync :-( The correct settings is TestOutputXml, not TestOutput (I believe this was a late change, which then of course went sour) Then , the parameter to the setting is a folder name, it seems you try to set a file name there. Since this is hard to change from the code, because this runs before any test code is executed, I think we need to change this behavious inside the adapter, so that it handles relative paths better, and then relative to the folder where the test is running. But, if you specify an absolute location you should be clear for now. I'll raise a separate issue to fix the relative path to behave better. |
@LirazShay I have just added a PR to fix the relative path issue (#596 ). I think that is what you need. If you want to try earlier, I have enclosed a pre-release debug version here Just unzip and you have the nuget package. Place it somewhere local. |
@OsirisTerje <?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<NUnit>
<TestOutputXml>C:\TestResults</TestOutputXml>
</NUnit>
</RunSettings> It saved the results XML in the specified folder with the name [TestProjectName].xml About the new version to fix the relative path, But when I put this row in the settings: <TestOutputXml>TestResults</TestOutputXml> It didn't save the xml in the bin folder of the test project. |
@LirazShay Are you sure there are not a folder below the bin named TestResults ? Also, if you look in the Output/Test window, it should state there which folder it will store to. You might have to set |
I think I have a problem with installing the pre-release debug version |
@LirazShay It is not a vsix, it is a nuget package so it is added to the solution directly. I have uploaded the vsix version with this comment. Please be aware you should uninstall it afterwards, since it will have the same version number as the upcoming release version - there is unfortunately no such thing as "pre-release" on vsix packages, only on nuget packages. You should try to move your solutions to the nuget adapter, it will also ease the use of them in CI environments. |
@LirazShay Yeah, I sent you a debug vsix, was a bit too quick there. I'll drop you a non-debug version later today, but then we know it works. |
@LirazShay Note: You must uninstall the former vsix first, then install this one, since they have the same version number. |
@OsirisTerje |
@OsirisTerje Excellent work :) |
@iWheeler5 Thanks! Good to hear it helps! I am planning on getting 3.13 out this week. I have one more issue I want to get in there, and then it should go. Just FYI, since that issue and PR is now merged, you can grab it off the pre-release feed. |
Does this work from Visual Studio 2022 test explorer or do I need to run the NUnit console from the command line? |
@naeemakram It works from VS. |
I am using Nunit 3 Test Adapter v3.17.0. My test.runsettings file is as below
while running test case from Microsoft Visual Studio Professional 2019 (v16.11.16) Test explorer, it is generating xml file in C:\TestResults folder like following:
but while running same test case from nunit3-console using following command i am getting different result: |
@Suban5 Looks like there are no tests there. Enable the dump execution file, and see what you got there. If there is nothing, your tests don't run. Also, try to update to 4.3.0 of the adapter. When I tested here now I got: |
Can you please tell me how to enable the dump execution file? |
Go here: https://docs.nunit.org/articles/vs-test-adapter/Tips-And-Tricks.html , and https://docs.nunit.org/articles/vs-test-adapter/Tips-And-Tricks.html#dumpxmltestdiscovery-and-dumpxmltestresults specific Then add a .runsettings file and include the property(ies) there like <RunSettings>
<NUnit>
<DumpXmlTestDiscovery >true</DumpXmlTestDiscovery >
<DumpXmlTestResults>true</DumpXmlTestResults>
</NUnit>
</RunSettings>
|
I have added DumpXmlTestDiscovery and DumpXmlTestResults in test.runsetings file. It is still generating the same XML file as I have commented above. I can assure you that my test is running as expected.
I am currently using nunit3TestAdapter from the visual studio marketplace extension instead of using it in Project and it is not showing any option to upgrade from 3.17.0.0 to the latest version. Can you please tell me why I am not getting the expected test output XML file? Is there any other way to get the test output XML file? |
In an empty folder: Run Add your runsettings file to the same folder (assuming it is named Then run dotnet test --logger "console;verbosity=normal" -s .runsettings or use it directly dotnet test --logger "console;verbosity=normal" -- NUnit.TestOutputXml=C:\TestResults |
You have to set the In the next version we will make this easier, so that if an absolute path is specified, then this mode is selected automatically., so sorry about this. |
Setting But setting
|
I am using Nunit adapter nuget package to integrate Nunit and visual studio. It is not generating TestResults.xml when i run nunit tests from test explorer.
I can do the same when i run it from Nunit3-console.exe.
The text was updated successfully, but these errors were encountered: