|
From: Steve F. <st...@m3...> - 2004-08-26 21:00:57
|
So why are you hiding ParameterClass? If it's only accessible via Main,
then the whole thing is packaged up in one and there's no point in being
picky. If UnderTest is callable elsewhere then ParameterClass has to be
visible anyway. If I wanted to be more controlled, I'd make
ParameterClass an interface and publish that.
S.
Alexey Kalinichenko wrote:
> Let me make sure I understand you. So if I have something like:
>
> //--------------------------------------------------------------
>
> class ParameterClass
>
> {
>
> public void DoSomething();
>
> }
>
> class UnderTest
>
> {
>
> public UnderTest(ParameterClass pc)
>
> {
>
> this.pc = pc;
>
> }
>
>
>
> public void UseIt()
>
> {
>
> pc.DoSomething();
>
> }
>
> }
>
> public class App
>
> {
>
> public static Main()
>
> {
>
> ClassUnderTest cut = new ClassUnderTest(new ParameterClass());
>
> cut.UseIt();
>
> }
>
> }
>
> //-------------------------------------------------------------------------------
>
> And I want to test ClassUnderTest in isolation, what do I do? Make
> ParameterClass public? I don't see it is a good idea to change it to public just
> for the testing purposes... Or did you mean something else?
>
> Thanks,
>
> Alexey
>
> >From: Steve Freeman <st...@m3...>
> >To: Alexey Kalinichenko <ak...@ho...>
> >Subject: Re: [Nmock-general] NMock and private/internal classes
> >Date: Thu, 26 Aug 2004 11:44:35 +0100
> >
> >Sorry to be facetious, but the short answer is not to test private
> >features, but to break things up so that you can test smaller public
> >components. I've become a lot less protective than I used to be
> >since moving to TDD.
> >
> >S.
> >
> >Alexey Kalinichenko wrote:
> >>I am new to NMock and have a basic question. Is mocking
> >>private/internal class supported by NMock? It doesn't work for me,
> >>I get MemberAccessException for the class ctor. I looked at the
> >>code and as far as I understand the mock class is created in a
> >>dynamic assembly and derived from the specified class. So in order
> >>for this to work the mocked class needs to be public.
> >> Is there any way around it? What is the preferred method of
> >>mocking private classes using NMock?
> >
|