[3.12.0.15]
I have a type TestCaseSource where I use .ToString() to write "null" if test case is null. The test case source is initialized in the fixture's static constructor.
However this function threw an exception due to a bug introduced (which I noticed due to dropped code coverage, no error was reported by NCrunch).
Now I want to log somehow when this function fails so user can tell where the error is located at, but neither Console.WriteLine or Trace.WriteLine will end up in NCrunch output (which I guess has something to do with log being written during test discovery).
Question: Is there any way I can write output to NCrunch log during the stage when NCrunch is iterating the test case sources?
Thanks.
Build/Test Issues
Log from class' ToString() used in TestCaseSource ?
Started by GreenMoose on 2,910 views
Remco NCrunch Developer
#11709
17 Jan 2018 08:47 UTC
Hi, thanks for posting.
I know of no mechanism that will allow you to write to the log from inside the discovery step. At this stage in the process, NCrunch doesn't have any hooks into the debug or console streams, so it's effectively deaf to everything you throw at it. One option for debugging code in this state is to add the following line of code to the TestCaseSource method:
System.Diagnostics.Debugger.Launch();
As soon as you enter this in, you'll be prompted to hook a debugger onto the code when NCrunch discovers tests. This should allow you to get more information about what is happening during the discovery run.
Another option is to just throw an exception, including information in the exception message. That should bubble up somewhere easily accessible.
I know of no mechanism that will allow you to write to the log from inside the discovery step. At this stage in the process, NCrunch doesn't have any hooks into the debug or console streams, so it's effectively deaf to everything you throw at it. One option for debugging code in this state is to add the following line of code to the TestCaseSource method:
System.Diagnostics.Debugger.Launch();
As soon as you enter this in, you'll be prompted to hook a debugger onto the code when NCrunch discovers tests. This should allow you to get more information about what is happening during the discovery run.
Another option is to just throw an exception, including information in the exception message. That should bubble up somewhere easily accessible.
Edited 17 Jan 2018 08:48 UTC
Remco wrote:Another option is to just throw an exception, including information in the exception message. That should bubble up somewhere easily accessible.
This does not seem to be the case since this was the original behavior (i.e. ToString() threw exception), NCrunch acts as if these tests "are not there" with gray coverage markers and no ">" marker ("test coverage marker").
The workaround I did, which seems to be good enough, was to simply return exception message in result for ToString(), then the developer will most likely see the awkwardness in the generated test name.
Thanks.
Post a reply
Log in to reply.