Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Log from class' ToString() used in TestCaseSource ?
GreenMoose
#1 Posted : Wednesday, January 17, 2018 8:06:11 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 503

Thanks: 142 times
Was thanked: 66 time(s) in 64 post(s)
[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.
Remco
#2 Posted : Wednesday, January 17, 2018 8:47:30 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
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.
GreenMoose
#3 Posted : Wednesday, January 17, 2018 9:36:14 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 503

Thanks: 142 times
Was thanked: 66 time(s) in 64 post(s)
Remco;11709 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.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.026 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download