-
Notifications
You must be signed in to change notification settings - Fork 15
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
Capture StdOut from Console.WriteLine calls #22
Comments
@IloSophiep Yes, I added this to the gitlab docs, glad it was helpful. I'm happy to dig into this in the next couple day. Were using the same integration with dotnet test as the trx logger, so I expect this would be straight forward. My intuition here is that the proper role of this library is to put the standard out into You may have seen, there are some command line flags specifically to reformat the report a little for GitLab. Best I can tell they only show the |
Like i tried to say in the initial post, that would be good enough for us for sure! That's also what we currently do with the TRX logger. We take the TRX report and declare it as an artifact for download if we need to check the test logging. We also take the TRX report and convert it to a junit XML report, so we can use parts of the gitlab web UI for displaying failures. If it is of any help, i could probably get you an example of the TRX report and the converted junit XML report on monday. |
@IloSophiep An example would be great. |
OK, i tried to prepare some example files. I've added a example-files.zip, which contains:
I hope it's not a problem i "censored" some parts slightly. |
@IloSophiep Great, looks like thats everything I need. Will let you know when there is a pre-release package for you to try. |
@IloSophiep After looking at it some more, here is what I think makes sense to do.
|
@IloSophiep please give pre-release 2.1.34 a try. I would suggest trying it like this to get output above in GitLab: |
We tested the preview today! To be honest: We struggled a bit with installing the pre-release and couldn't get it to work on our CI server, because of Nuget proxies - but we were able to test the changes locally at least and check the result XML. The result looks good and pretty much like what we had hoped for. I only later realized that the junit format does not seem to support saving the stdout as nicely as the TRX, but i think you found a decent way to work around that. We thought that maybe it would be even better to format the "blocks" in the Apart from that: Thanks for the fast work, much much appreciated! |
@IloSophiep Agreed, JUnit doesn't store the output as cleanly as trx. Give 2.1.36 a try. I added some indentation to try and clean up the output. I think its easier to read the output now. |
Looks good to me, yeah. Three things:
All of those are not really problems, just things i noticed |
@IloSophiep @Siphonophora is below a fair statement on the logging scope?
Now test run can include multiple assemblies, so the logging captured in (2) must be grouped on a per assembly basis? (2) is more complex and test framework dependent. Is it a blocker for this issue? I'm thinking (2) should be solved at a different abstraction we're planning to build (spekt/testlogger). |
@codito I double checked and the schema I am using for Junit https://github.com/windyroad/JUnit-Schema/blob/master/JUnit.xsd includes only 1 level of system-out and system-err, at the test-suite level. So, I'm accumulating all the standard out to the test-suite level. That's why I included the command line flags to include test specific error messages in the At the moment, I believe the library is only capable of running on one assembly at a time. My impression is that dotnet test was creating an instance of our logger for each assembly it ran tests on. Totally un-related. Any reason not to add the spekt logo to the nuget package? |
Here's the junit xsd which led me to believe that there are 2 levels of system-out: https://github.com/junit-team/junit5/blob/master/platform-tests/src/test/resources/jenkins-junit.xsd Any idea if this xsd is supported by gitlab? Which is the official one? Or we need to support both? We can combine all outputs to the test-suite scope, not sure if that will help the user a lot since they need to find which test had the output. We can workaround that by prefixing the test name etc. probably. I think (1) would be the simplest unambiguous approach if it's supported by gitlab :) Adding logo to the package is a good idea. Should we track it as a separate issue? |
From a quick search, it appears gitlab may be supporting |
Agreed. Logo is now #24 Picking which xsd to support was pretty difficult when this was getting started. I couldn't find anything that looked like a solid standard and left the disclaimer in the docs. We had an issue #16 before about producing xml that didn't validate against a particular xsd. We are now validating against the schema in our docs during the unit tests. Switching to the Jenkins schema would cause a failure, but it doesn't seem like its intentional. Actual file doesn't specify minimum occurrences for property. The dotNet xml validation treats that like <xs:element ref="property" maxOccurs="unbounded"/> Probably should be this, in which case we pass: <xs:element ref="property" minOccurs="0" maxOccurs="unbounded"/> I do keep a mini pipeline setup on gitlab to test how the xml is displayed. <testcase name="MathTests.Multiply_ReturnsEight(1,0)" classname="ExampleTests.MathTests" time="0.016">
<failure message="Assert.AreEqual failed. Expected:<2>. Actual:<1>. " type="not specified">
Assert.AreEqual failed.
Expected: 8
But Was: 0
Stack Trace:
at ExampleTests.MathTests.TestMethod2() in P:\ath\MathTests.cs:line 38
Standard Output:
Input a: 1
Input b: 0
Result 0
</failure>
<system-out>Here is some output.</system-out>
</testcase> Produces this UI: Thats consistent with what I have seen. Gitlab only uses a few pieces of the schema, so in order to get the standard output to show, I am putting it inside the failure body. If we use the new elements on the Jenkins schema the output will be clearer. But then any parser using the Ant schema would fail, which we know would happen to some users due to #16. What do you think about sticking with the current schema and opening tickets with Junit and Gitlab. Might also be worth it to reach out to circleCI / others to find out what they are doing. Then it will be easier to decide whether to support both schemas |
@Siphonophora thanks for the investigation!
Makes sense. Let's move ahead with (2). We will come back to (1) as needed in future. From #22 (comment)
This is true for We need to consider concurrency (for the case when tests may be running in parallel) in TestRunMessageHandler. Probably use a lock as rest of the code does? |
@codito After a little more digging, the Junit team has a long running issue related to creating a new xsd. junit-team/junit5#373 Also, the Jenkins schema was added to that project 4 years ago, so it isn't exactly new. Agreed, if it can run in parallel it will need some locking, or maybe one of the concurrent collections to make that safe. I will push resolutions to your comments and some formatting things @IloSophiep found later today. |
Hey guys, I'm looking forward for this feature, I need the standard output to be printed out in the xml file just like the xunit testlogger does. |
@jdelucca Here is the newest package from Pull #23. If you do try it, please let us know how it behaves. https://www.myget.org/feed/spekt/package/nuget/JunitXml.TestLogger/2.1.40 |
I got a bump about this issue, thanks to your comments. To be honest: For now we're still just using the workaround with trx2junit in our CI - that said, i don't want to apply any pressure on how fast this point needs to be resolved. If a proper solution needs time, i won't complain. |
@IloSophiep I have been thinking a bit about the status of the PR. I'm pretty confident we are getting all the stdout and stderr into the xml report with these changes. I'm less confident we have the 'ideal' format for that text within the xml. Given that we know the xml is still compliant with the spec and the stdout is for human review, my thought is we could safely make any change to the format without needing to consider it a breaking change. I don't use this sort of output in my own unit tests, so I haven't been able to do too much testing. If either you or @jdelucaa could give some feedback that would be great. If nothing jumps out as needing fixes, then I would tend to try and get this out in the field soon. @jdelucaa Unrelated to the above. I am curious about your CI setup. If you sometimes need xunit and sometimes junit reports, I would be interested to learn why. |
Hey @Siphonophora , Thanks for the quick response. I tested it and it's exactly what I was looking for, one suggestion would be to write the output right after each test, like the xunit logger does, but it would be just an improvement, this already looks good. :) About my CI setup: |
@jdelucaa Thanks for the feedback. I think you may want this flag: |
@Siphonophora Ok, thanks. |
@Siphonophora 👍 let's roll this out fast to unblock everyone. |
@IloSophiep @jdelucaa This has been released in https://github.com/spekt/junit.testlogger/releases/tag/v2.1.78 |
Context
At work we've recently switched a selenium project form .NET Framework to .NET core and are using
dotnet test
to execute the tests. Since we're using gitlab CI we needed a junit report, so we used this package's logger and in theory it works great.The only problem, why we've "had to" switch to a combination of "trx logger + trx2junit" is, that we use
Console.WriteLine(...)
quite a lot to print information during the tests and sadly this logger does not seem to support those.Request
It would be great to have the values send to
Console.WriteLine(...)
dotnet test --logger junit
-call (that way the logging would show up in the job's log) OR / ANDAs an aside: Thanks a lot for this project, and (i think) contributing to the gitlab documentation!
The text was updated successfully, but these errors were encountered: