Results 1 to 2 of 2

Thread: nunit and abstract classes

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Location
    didn't decide yet
    Posts
    222

    nunit and abstract classes

    Hi i m just got into the nunit world and i m facing the following problem .

    i have an abstract class like
    Code:
    [TestFixture]
    	public abstract class ConnectionFixture
    	{
    		private OleDbConnection connection;
    		[TestFixtureSetUp]
    		public void OpenConnection()
    		{
    			this.connection=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ConfigurationSettings.AppSettings.Get("databasePath"));
    			this.connection.Open();
    		}
    		
    
    		[TestFixtureTearDown]
    		public void CloseConnection()
    		{
    			this.connection.Close();
    		}
    		public OleDbConnection Connection
    		{
    			get {return this.connection;}
    		}
    
    	}
    and i want some other classes to inherit the above like

    Code:
    	[TestFixture]
    	public class UserFixture:ConnectionFixture
    	{
    		private User insertedUser;
    		[TestFixtureSetUp]
    		public void SetUp()
    		{
    			insertedUser=new User(Connection);
    			insertedUser.Name="testUser";
    			insertedUser.ReceiptCountInterval=1;
    			insertedUser.ReceiptTimeIntervalStart=DateTime.Now;
    			insertedUser.ReceiptTimeIntervalStop=DateTime.Now;
    			insertedUser.Save();
    
    			Assert.IsTrue(insertedUser.ID>0);
    		}
    but using that design the openConnection method is never executed. How can i make it to execute only once?
    Come and get our ISDN CallerID http://www.3wm.biz

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    Hmmm....not sure where to start on this one. When you think of NUnit, think of simple tests; that's not where you're going with this post. Not sure what a ConnectionFixture is but if the intention is that it's anything related to NUnit and TestFixtures you've missed the point. Tests should be isolated from each other. Based on your example your test should be more like this:
    PHP Code:
    [TestFixture]
    public class 
    UserTests
    {
        [
    Test]public void SaveTest()
        {
            
    User insertedUser = new User();
            
    insertedUser.Name="testUser";
            
    insertedUser.ReceiptCountInterval=1;
            
    insertedUser.ReceiptTimeIntervalStart=DateTime.Now;
            
    insertedUser.ReceiptTimeIntervalStop=DateTime.Now;
            
    insertedUser.Save();
            
    Assert.IsTrueinsertedUser.ID );
        }

    With the design you're going with, the details of connecting to the database are really hidden( or at least should be ) from the client of your User class.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width