Bug 4116 - "show test source code" is disabled for tests marked with the TestCase or TestCaseSource attribute
Summary: "show test source code" is disabled for tests marked with the TestCase or Tes...
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: NUnit ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Mike Krüger
URL:
Depends on:
Blocks:
 
Reported: 2012-03-27 19:32 UTC by Csaba Halász
Modified: 2012-03-29 12:04 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Csaba Halász 2012-03-27 19:32:57 UTC
Given this sample code:

using NUnit.Framework;
namespace Test
{
	[TestFixture]
	class TestClass
	{
		[Test]
		[TestCase(false)]
		void Test1(bool flag)
		{
		}
	}
}

The "show test source code" is disabled (greyed out) in the context menu for both nodes - that is "Test1" and "Test1(false)" - in the "unit tests" tree. Same thing happens if the test cases are provided using a TestCaseSource attribute.
Comment 1 Csaba Halász 2012-03-27 20:37:09 UTC
Execution ends up in NUnitAssemblyTestSuite.GetSourceCodeLocation which looks like this:

        internal SourceCodeLocation GetSourceCodeLocation (UnitTest test)
        {
                if (test is NUnitTestCase) {
                        NUnitTestCase t = (NUnitTestCase) test;
                        return GetSourceCodeLocation (t.ClassName, t.Name);
                } else if (test is NUnitTestSuite) {
                        NUnitTestSuite t = (NUnitTestSuite) test;
                        return GetSourceCodeLocation (t.ClassName, null);
                } else
                        return null;
        }


Apparently the parent is an instance of NUnitTestSuite with ClassName "Test.TestClass.Test1". So this goes to the second block.

The leaf node is an instance of NUnitTestCase, with ClassName "Test.TestClass.Test1" and Name "Test1(False)". So this goes to the first block.

In both cases, the class name wrongly includes the method name. For the suite, method lookup is not even attempted, while for the test case itself, the name won't match the method name (that's assuming the class name is fixed).
Comment 2 Mike Krüger 2012-03-29 12:04:59 UTC
fixed that one - the 'ClassName' is wrong, I removed that property - it's a virtual name that has nothing to do with the type level.

I needed to add the type level things to make it work.