← Back to team overview

nunit-core team mailing list archive

[Bug 633884] Re: TestCaseSource does not use Arguments, Categories etc as described in documentation for 2.5.7

 

It is a logical deduction from the description at
http://nunit.org/index.php?p=testCaseSource&r=2.5.7

>From there I read:
"If sourceType is not specified, the class containing the test method is used. NUnit will construct it using either the default constructor or - if arguments are provided - the appropriate constructor for those arguments.

The sourceName argument represents the name of the source used to
provide test cases. It has the following characteristics:

...
    * It must return an IEnumerable or a type that implements IEnumerable.
    * The individual items returned by the enumerator must be compatible with the signature of the method on which the attribute appears. The rules for this are described in the next section. "

and

"Constructing Test Cases

In constructing tests, NUnit uses each item test case returned by the enumerator as follows: 
...
If it is any other type of object, it is examined using reflection and any public fields or properties with the following names are used:
...
Categories
    An IList of categories to be applied to the test case. 
...
TestName
    Provides a name for the test. If not specified, a name is generated based on the method name and the arguments provided 
Ignored
    If true, the test case is ignored. 

.... "

Here is the key reason I expect it to work - you say:
***" it is examined using reflection and any public fields or properties with the following names are used:"***.  

"It" is "each item test case returned by the enumerator".  In my case
(see below for actual code), "it" is an instance of class
SimTestDescriptor.  You'll see it has public TestName amongst others.
Since I expose that, I expect it to be used according to your
explanation; ditto Categories and Ignored.

Here are the signatures (comments etc. excluded):

[TestCaseSource(typeof(SimTestDataGenerator), "TestArguments")]
public void Test1(SimTestDescriptor descriptor)

public class SimTestDataGenerator
{
		public SimTestDataGenerator()
...
		public IEnumerable<SimTestDescriptor> TestArguments()
...
}

		
public class SimTestDescriptor
{
        public SimTestDescriptor(string category, string note, string simFile, bool update, Regression.RunLocation runLocation, ThreadMode threadMode, ShockFileAction shockFileAction, string baseLineCulture, string versionUnderTestCulture)
...        
        public string TestName { get; private set; }
        public IList<string> Categories { get; private set; }
        public string Note;
        public string SimFile;
        public bool Update;
        public Regression.RunLocation RunLocation;
        public ThreadMode ThreadMode;
        public ShockFileAction ShockFileAction;
        public string BaselineCulture;
        public string VersionUnderTestCulture;
        public bool Ignored;
}

-- 
TestCaseSource does not use Arguments, Categories etc as described in documentation for 2.5.7
https://bugs.launchpad.net/bugs/633884
You received this bug notification because you are a member of NUnit
Developers, which is subscribed to NUnit V2.

Status in NUnit V2 Test Framework: New

Bug description:
What happens:

Created a class X that is returned as an IEnumerable<X> in method M of class Z.  
This is used in [TestCaseSource(typeof(Z), "M"]

Class X has been given

		public string TestName { get; private set; }

		public IList<string> Categories { get; private set; }

		public bool Ignored;

In the constructor for X,  these have been initialised
			this.Categories = new List<string> { "foo" };
			this.TestName = note;
			this.Ignored = true;

The test is executed(contrary to Ignored==true).
There are no categories in the NUinit GUI.
The test is not renamed.

What I expect:
The test is flagged as ignore.
There is a category "foo".
The test is named after the string value in TestName.

NUnit 2.5.7.
Nunit.exe (GUI)





Follow ups

References