If it is the case that the whole structure has to be valid for the test to 
pass, I would create a function to validate the structure that would return 
zero or more error messages (with an empty string being "No Errors").  I would 
include a single assert that required the returned error string to be equal to 
the empty string.  If the structure was valid, the returned error message 
string would be empty and the test would pass.  if the structure was not valid, 
the returned error message string would not be empty and the test would fail, 
and in the process of failing would report the differences between the empty 
message and the actual message.  This is the best of both worlds.Jon Stonecash

> Date: Fri, 4 Jan 2008 15:50:57 +0000> From: [EMAIL PROTECTED]> Subject: 
> [ADVANCED-DOTNET] Unwiedly unit test> To: 
> ADVANCED-DOTNET@DISCUSS.DEVELOP.COM> > Hi all,> > I am just looking for some 
> guidance.> > I have the following monstrous unit test (see below) where I 
> seem to be testing bout 10 different tests in the same unit test.> > The 
> problem is that it is a work flow type of situation and I need the data to be 
> in a certain state before I finally test the bit of functionality 
> (planController.AttemptSignOff;.> > If I split it up into different tests 
> then I am retesting everything each time and duplicating code. This is even 
> the case if I start using helper methods.> > The guidelines say that unit 
> tests should only test one thing and one thing only.> > I simply cannot see 
> how I can break this up. > > Any words of advice from the more knowledgeable 
> out there?> > [Test]> public void Sign_off_Process()> {> Plan plan = null;> 
> PlanController planController = GetPlanController();> 
> _mockRepository.ReplayAll();> try> {> plan = 
> SavePlanAsSystemAdmin(planController);> Guid planUid = plan.Uid;> 
> planController.AddSignOffContact(plan, GetFirstItem<Contact>());> 
> _mockRepository.BackToRecord(_mockEmailSender);> _mockEmailSender.Send(null, 
> null, null, null, null);> LastCall.IgnoreArguments();> 
> _mockRepository.ReplayAll();> planController.RequestSignOff(plan, 
> "testurl");> _mockRepository.VerifyAll();> plan = 
> planController.LoadPlan(planUid);> SignOffContact signOffContact = 
> plan.SignOffList[0];> Assert.IsTrue(plan.ReadOnly);> 
> Assert.AreEqual(plan.MajorVersion, signOffContact.VerMajor);> 
> Assert.AreEqual(plan.MinorVersion, signOffContact.VerMinor);> 
> Assert.AreEqual(false, plan.SignOffOperators[0].SetUp);> Assert.AreEqual(1, 
> signOffContact.Requested);> Guid signOffOperatorUid = 
> plan.SignOffOperators[0].Uid;> SignOffOperator signOffOperator = 
> planController.GetSignOffOperator(signOffOperatorUid);> Assert.AreEqual(1, 
> signOffOperator.Plans.Count);> plan = signOffOperator.Plans[0];> 
> Assert.IsNotNull(plan);> Assert.IsFalse(signOffOperator.SetUp);> string 
> validLogIn = "1234";> string invalidLogIn = "12345";> signOffOperator.Pin = 
> "ABCD";> Assert.IsFalse(planController.IsValid(signOffOperator));> 
> signOffOperator.Pin = validLogIn;> 
> Assert.IsTrue(planController.IsValid(signOffOperator));> 
> planController.SetUpSignOffOperator(signOffOperator);> signOffOperator = 
> planController.GetSignOffOperator(signOffOperatorUid);> 
> Assert.IsTrue(signOffOperator.SetUp);> 
> Assert.IsFalse(planController.LogInSignOffOperatorWithPin(signOffOperatorUid, 
> invalidLogIn));> 
> Assert.IsTrue(planController.LogInSignOffOperatorWithPin(signOffOperator, 
> validLogIn));> Assert.AreEqual(1, 
> planController.SignOffOperatorsPlanList(signOffOperatorUid).Count);> 
> _mockRepository.BackToRecord(_mockEmailSender);> _mockEmailSender.Send(null, 
> null, null, null, null);> LastCall.IgnoreArguments();> 
> _mockRepository.ReplayAll();> 
> planController.AttemptSignOff(signOffOperatorUid);> 
> _mockRepository.VerifyAll();> }> catch (Exception ex)> {> _log.Error(ex);> 
> Assert.Fail(ex.Message);> }> finally> {> if ((plan != null) && 
> (!plan.IsNew))> planController.DeletePlan(plan.Uid);> }> }> [EMAIL 
> PROTECTED]> 
> _________________________________________________________________> Who's 
> friends with who and co-starred in what?> 
> http://www.searchgamesbox.com/celebrityseparation.shtml> 
> ===================================> This list is hosted by DevelopMentorĀ® 
> http://www.develop.com> > View archives and manage your subscription(s) at 
> http://discuss.develop.com
===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to