Re: Multiple Constructors - Please help!

"Nassar, Anthony" <[email protected]>
Newsgroups gmane.comp.windows.dotnet.nunit.user
Message-ID <[email protected]>
I think that what you want is something like this. The class
TestFixtureAttribute is declared like this:
[AttributeUsage
<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:
1.0.5000.0:b77a5c561934e089/System.AttributeUsageAttribute/.ctor(System.
AttributeTargets)> (AttributeTargets
<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:
2.0.0.0:b77a5c561934e089/System.AttributeTargets> .Class
<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:
2.0.0.0:b77a5c561934e089/System.AttributeTargets/Class> , AllowMultiple
<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:
1.0.5000.0:b77a5c561934e089/System.AttributeUsageAttribute/property:Allo
wMultiple:Boolean> =false, Inherited
<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:
1.0.5000.0:b77a5c561934e089/System.AttributeUsageAttribute/property:Inhe
rited:Boolean> =true)]
public sealed class TestFixtureAttribute
<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://nunit.fra
mework:2.4.4.0:96d09a1eb7f44a77/NUnit.Framework.TestFixtureAttribute>  :
Attribute
<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:
1.0.5000.0:b77a5c561934e089/System.Attribute> 
{
    // Fields
    private string
<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:
1.0.5000.0:b77a5c561934e089/System.String>  description
<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://nunit.fra
mework:2.4.4.0:96d09a1eb7f44a77/NUnit.Framework.TestFixtureAttribute/des
cription:String> ;

    // Methods
    public TestFixtureAttribute
<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://nunit.fra
mework:2.4.4.0:96d09a1eb7f44a77/NUnit.Framework.TestFixtureAttribute/.ct
or()> ();

    // Properties
    public string
<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:
1.0.5000.0:b77a5c561934e089/System.String>  Description
<http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://nunit.fra
mework:2.4.4.0:96d09a1eb7f44a77/NUnit.Framework.TestFixtureAttribute/pro
perty:Description:String>  { get; set; }
}
...so if you apply it to the abstract base class, the derived classes
will inherit it, and the NUnit test runner will find it. Anyway:
[TestFixture]
public class AbstractSomethingFixture {
    protected abstract Image CreateImage();
    protected Image image;
    [SetUp] 
    public void SetUp() {
        this.image = this.CreateImage();
    }
    [Test]
    public void FirstTest() {
        // Do something with this.image;
    }
    [Test]
    public void SecondTest() {
        // Do something else with this.image;
    }
    [Test]
    public void YetAnotherTest() {
        // Blah blah blah.
    }
}
public class RealSomethingFixture1 : AbstractSomethingFixture {
    protected Image CreateImage() {
        // Return an instance of the image, by calling the constructor
of your choice.
    }
}
public class RealSomethingFixture2 : AbstractSomethingFixture {
    protected Image CreateImage() {
        // Return an instance of the image, by calling a different
constructor.
    }
}



________________________________

	From: James Snell [mailto:[email protected]] 
	Sent: Wednesday, December 19, 2007 5:23 PM
	To: Nassar, Anthony
	Subject: Re: [Nunit-users] Multiple Constructors - Please help!
	
	
	Thanks a ton Anthony!
	
	I only first started looking at NUnit yesterday, so I still have
a bit to learn with respect to it's use. So as it stands, I'm still
somewhat confused as to how to apply your suggestion to my code... 
	
	As it stands, my test suite starts with:
	
	namespace UnitTests 
	{
	
	    [TestFixture]
	    public class ImageSuite
	    {
	       [SetUp]
	        public void setup()
	        {
	            <stuff> 
	        }
	
	        [Test] 
	        public void Constructor1Test() {
	            <stuff>
	        }
	
	
	        [Test] 
	        public void Constructor2Test() {
	            <stuff>
	        }
	
	
	        [Test] 
	        public void Constructor3Test() {
	            <stuff>
	        }
	
	
	Could you possibly help me a bit further by illustrating where
[Abstract Factory] & [TestFixtureAttribute] go..
	
	Thanks a ton! You'll get credit in the header of the source code
at least until someone else potentially removes it.. :) 
	
	  James
	
	
	
	
	On 12/19/07, Nassar, Anthony <[email protected]
<mailto:[email protected]> > wrote: 

		Create an abstract fixture class with an "abstract
factory" method that instantiates the object for the setup method? Then
subclass as necessary. I believe that if [TestFixtureAttribute] is on
the abstract class, the derived classes will inherit it. If not, don't
worry; just put the attribute on the derived classes. [Test] can go on
the methods of the abstract base class. 


________________________________

			From: [email protected]
<mailto:[email protected]>
[mailto:[email protected]
<mailto:[email protected]> ] On Behalf Of James
Snell
			Sent: Wednesday, December 19, 2007 5:06 PM
			To: [email protected]
<mailto:[email protected]> 
			Subject: [Nunit-users] Multiple Constructors -
Please help!
			
			
			
			Hey gang,
			   I've just started implementing unit tests for
a project at work and I've been asked to give NUnit a try for it.
			
			  The challenge I've got is I need to imeplement
unit tests for a class that is rather large. The key problem I'm dealing
with is that it has 3 totally different constructors. For each
constructor I must run the entire test suite once. At this point the
only way I can think of doing that is to effectively just cut and paste
the entire suite 3 times and make the minor changes necessary for the
SetUp() of them. Either that or by just having one suite and manually
commenting out two out of three constructors and manually rerunning the
test suite 3 times. I figure there's got to be a better way of doing
this. The code I'm testing is C++, for the most part, my existing suite
for NUnit is a C# implementation. 
			
			  Does anyone know of a means of testing all the
constructors gracefully!? I'd really really appreciate some help.
			
			  Thanks,
			     James

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

_______________________________________________
Nunit-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nunit-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.