Any of our unit tests which inherit from UnitTestSpecification are slow.  It
is fine up until the EstablishContext method and inside EstablishContext it
is the MockRepository.GenerateStub which is slow.  I haven't posted all the
code but this should be enough to get an idea of how the test looks.  And we
are running them with the Resharper Test Runner, though I have also tried
running them from the NUnit GUI and it is the same result - still slow.
 public abstract class UnitTestSpecification
{
[TestFixtureSetUp]
public virtual void BaseSetup()
{
m_autoStubContainer = IOC.Initialize(new AutoStubDependencyContainer());
m_autoStubContainer.AutoStubEnabled = AutoStubEnabled;

EstablishContext();

Given();

CreateSubject();

if (HandleExceptions)
{
try
{
When();
}
catch (Exception ex)
{
LastException = ex;
}
}
else
{
When();
}
}

[TestFixtureTearDown]
public virtual void BaseTearDown()
{
LastException = null;

         DateTimeExtended.UseCurrentServerDateTime();

CleanUp();

clsWebConfig.CurrentConfiguration = null;
}

protected virtual void EstablishContext()
{
Logger = MockRepository.GenerateStub<ILogger>();
 DALFactory = StubRegistered<IDALFactory>();

ResourceDAL = MockRepository.GenerateMock<IResourceDAL>();
SkillDAL = MockRepository.GenerateMock<ISkillDAL>();
TrainingDAL = MockRepository.GenerateMock<ITrainingDAL>();
UserDAL = MockRepository.GenerateMock<IUserDAL>();
GroupDAL = MockRepository.GenerateMock<IGroupDAL>();
ReportDAL = MockRepository.GenerateMock<IReportDAL>();
            AuthenticatedUser = StubRegistered<IAuthenticatedUser>();
CertificateManager = StubRegistered<ICertificateManager>();
CertificateCreator = StubRegistered<ICertificateCreator>();
FileIO = StubRegistered<IFile>();
SkinManager = StubRegistered<ISkinManager>();
CurrentSkin = StubRegistered<IclsSkinBL>();

SkinManager.Stub(s => s.GetBranding()).Return("master");
            SkinManager.Stub(x => x.GetCurrentSkin()).Return(CurrentSkin);
            DALFactory.Stub(x => x.GetResourceDAL()).Return(ResourceDAL);
DALFactory.Stub(x => x.GetSkillDAL()).Return(SkillDAL);
DALFactory.Stub(x => x.GetTrainingDAL()).Return(TrainingDAL);
DALFactory.Stub(x => x.GetUserDAL()).Return(UserDAL);
DALFactory.Stub(x => x.GetReportDAL()).Return(ReportDAL);
DALFactory.Stub(x => x.GetGroupDAL()).Return(GroupDAL);

DateTimeExtended.UseCurrentServerDateTime();
}

protected virtual void Given()
{
}

protected virtual void CreateSubject()
{
}

protected abstract void When();

protected virtual void CleanUp()
{
}

protected T MockRegistered<T>()
where T : class
{
if (!Container.IsRegistered<T>())
{
Container.Register<T>(MockRepository.GenerateMock<T>());
}

return Container.Resolve<T>();
}

protected T StubRegistered<T>()
where T : class
{
if (!Container.IsRegistered<T>())
{
Container.Register<T>(MockRepository.GenerateStub<T>());
}

return Container.Resolve<T>();
}
}
 public abstract class InstanceSpecification<TSubject> :
UnitTestSpecification
{
public TSubject TestSubject
{
get;
private set;
}

protected override void CreateSubject()
{
TestSubject = Initialize_subject_under_test();
}

protected abstract TSubject Initialize_subject_under_test();
}
  [TestFixture]
public class When_task_completes_successfully :
InstanceSpecification<ActionUserEventTask>
{
private int m_userID1;
private int m_userID2;
private IUserTrainingEventService m_userTrainingEventService;
private DateTime m_eventDate;

protected override void Given()
{
m_eventDate = DateTimeExtended.ServerTimeNow.Date;

m_userID1 = 1;
m_userID2 = 2;

m_userTrainingEventService =
MockRepository.GenerateStub<IUserTrainingEventService>();

TrainingDAL.Stub(x => x.GetUserTrainingEventUserIDs(m_eventDate,
UserTrainingEvent.StatusCode_EventPending))
   .Return(new[] { m_userID1, m_userID2 });

}

protected override ActionUserEventTask Initialize_subject_under_test()
{
return new ActionUserEventTask(m_eventDate, m_userTrainingEventService);
}

protected override void When()
{
TestSubject.Execute();
}

[Test]
public void It_should_not_throw_an_exception()
{
Assert.IsNull(LastException);
}

[Test]
public void
It_should_instruct_each_user_with_pending_training_events_to_action_those_events()
{
m_userTrainingEventService.AssertWasCalled(x =>
x.ActionUserTrainingEvents(Arg.Is(m_userID1), Arg.Is(m_eventDate)));
m_userTrainingEventService.AssertWasCalled(x =>
x.ActionUserTrainingEvents(Arg.Is(m_userID2), Arg.Is(m_eventDate)));
}
}


2009/9/18 Tim Barcz <[email protected]>

> So it's only slow when you're running the tests through .... TDD.NET?
> Resharper Test Runner?
>
> Can you post a complete test that is slow?
>
>
> On Thu, Sep 17, 2009 at 10:33 PM, Russell Wilson <[email protected]>wrote:
>
>> Ahh to clarify when I said testing asp.net I meant just running the
>> application from visual studio and using the debugger.
>>
>>
>> 2009/9/18 Tim Barcz <[email protected]>
>>
>>> Can you clarify how exactly you're testing asp.net?
>>>
>>> Please post a sample of the slow test (complete).
>>>
>>>
>>> On Thu, Sep 17, 2009 at 7:12 PM, rtw <[email protected]> wrote:
>>>
>>>>
>>>> Hi all,
>>>>
>>>> I have been using rhino mocks 3.5.0.0 for the last 6 to 12 months and
>>>> it has really transformed the way we write unit tests.  Up until the
>>>> last few days I have been able to debug and step into my unit tests
>>>> and it would run roughly the equivalent speed as when debugging our
>>>> asp.net application.
>>>>
>>>> In the last few days however debugging (of tests only the asp.net is
>>>> fine) has been painfully slow, i mean it takes 5 to 10 minutes just to
>>>> hit my first break point where it used to take a couple of seconds.
>>>> The methods which seem to take a long time when called is
>>>> MockRepository.GenerateStub<ISomething>().  At first I tried all the
>>>> usual things like deleting all temp files, cleared up heaps of space
>>>> on the HDD and ran a defrag etc. I even tried using version 3.6.0.0
>>>> dlls and I still had the performance problem.
>>>>
>>>> Has any one encountered a similar issue ? or does anyone out there
>>>> have any insight into the possible cause and solution to the
>>>> problem ?
>>>>
>>>> Im going crazy trying to figure this out so any help is most
>>>> appreciated.
>>>>
>>>>
>>>> Cheers,
>>>> russell
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Tim Barcz
>>> Microsoft ASPInsider
>>> http://timbarcz.devlicio.us
>>> http://www.twitter.com/timbarcz
>>>
>>>
>>>
>>>
>>
>>
>>
>
>
> --
> Tim Barcz
> Microsoft ASPInsider
> http://timbarcz.devlicio.us
> http://www.twitter.com/timbarcz
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rhinomocks?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to