← 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

 

Indeed! I see the problem. I'm afraid it's a documentation bug.

There should be an additional element in the list under "Constructing
Test Cases"

0. If the test has a single argument and the returned value matches the type of
that argument it is used directly.

This is a case where the author (me) thought that was "obvious" - but clearly
it is not.

If you want your test to process the contents of your own struct or class, then
use it as an argument and return that type. If you want NUnit to perform
processing described, then the actual arguments should be stored in an
Arguments member. In fact, in that case, you may as well use TestCaseData,
which contains all the functionality you are looking for and will also continue
to work under NUnit 3.0, where we no longer use reflection in this way.

Sorry for the confusion.

Charlie


On Fri, Sep 10, 2010 at 1:51 AM, Hamish Gunn <633884@xxxxxxxxxxxxxxxxxx> wrote:
> 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.
>

** Changed in: nunitv2
       Status: New => Triaged

** Changed in: nunitv2
   Importance: Undecided => Medium

** Changed in: nunitv2
     Assignee: (unassigned) => Charlie Poole (charlie.poole)

** Changed in: nunitv2
    Milestone: None => 2.5.8

-- 
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: Triaged

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)





References