Unit testing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pete

    #1

    Unit testing

    Hi folks,

    I've been looking at unit testing frameworks (csUnit, NUnit, etc) and have
    gathered some info on them (see the older thread on c# 2004). My question is
    this: how do they work with windows forms?

    All the samples I've seen are for trivial testing, such as making sure a
    property sets it's value correctly. How would I go about testing, for
    example, a custom control? All my testing seems to be visual (i.e. compile,
    run, see if it looks okay).. am I missing something?

    It seems to me that unit testing frameworks are of little use here.

    Pete


  • William Stacey

    #2
    Re: Unit testing

    http://www.nunit.org/default.htm is free and pretty good. And you can
    write your test cases in c# which is natural.

    --
    William Stacey, DNS MVP

    "Pete" <pvidler@gawab. com> wrote in message
    news:gJG5b.184$ 5X3.356985@news fep2-gui.server.ntli .net...[color=blue]
    > Hi folks,
    >
    > I've been looking at unit testing frameworks (csUnit, NUnit, etc) and have
    > gathered some info on them (see the older thread on c# 2004). My question[/color]
    is[color=blue]
    > this: how do they work with windows forms?
    >
    > All the samples I've seen are for trivial testing, such as making sure a
    > property sets it's value correctly. How would I go about testing, for
    > example, a custom control? All my testing seems to be visual (i.e.[/color]
    compile,[color=blue]
    > run, see if it looks okay).. am I missing something?
    >
    > It seems to me that unit testing frameworks are of little use here.
    >
    > Pete
    >
    >[/color]


    Comment

    • Pete

      #3
      Re: Unit testing

      Hi,

      William Stacey wrote:[color=blue]
      > http://www.nunit.org/default.htm is free and pretty good. And you
      > can write your test cases in c# which is natural.[/color]

      Did you actually read my message (I mentioned nunit)? My problem is how to
      add test cases to windows forms controls (custom controls of my design) in a
      useful way.

      All the unit testing frameworks (for c#) work in virtually the same way.
      NUnit is not unique, or even necessarily the best. Coupled with the fact
      that their website seems to completely lack any info on typical/advanced
      usage patterns, that link is not too useful to me.

      -- Pete


      Comment

      • Arild Fines

        #4
        Re: Unit testing

        Pete wrote:[color=blue]
        > Hi folks,
        >
        > I've been looking at unit testing frameworks (csUnit, NUnit, etc) and
        > have gathered some info on them (see the older thread on c# 2004). My
        > question is this: how do they work with windows forms?
        >
        > All the samples I've seen are for trivial testing, such as making
        > sure a property sets it's value correctly. How would I go about
        > testing, for example, a custom control? All my testing seems to be
        > visual (i.e. compile, run, see if it looks okay).. am I missing
        > something?
        >
        > It seems to me that unit testing frameworks are of little use here.[/color]

        The general idea is to put as little actual functionality in the GUI layer
        as possible. Instead factor out the "meat" of the application into separate
        classes which have no knowledge of the GUI layer. These classes can then be
        tested using a unit testing framework.

        --
        Arild Fines


        A Visual Studio .NET Addin for the Subversion version control system.


        Comment

        • Dmitriy Lapshin [C# / .NET MVP]

          #5
          Re: Unit testing

          Hi William (fellow MVP I suppose?),
          [color=blue]
          > Well it can still be usefull. A form is just a class right. You can't[/color]
          test[color=blue]
          > the visual look of the form easily, but you can test its function. You[/color]
          can[color=blue]
          > create an instance of a form, plug in test data or set control values, hit
          > buttons and read results from text boxes, etc. So you can test form
          > function and exceptions, and if things are visable or other properties on
          > the form/controls, etc.[/color]

          A form is not just a class - it is also a window and therefore requires a
          message pump to work. To the best of my knowledge, the message pump is
          implemented in the Application class, so you will probably need to
          instantiate one to run a form as a form and as not just a class.

          --
          Dmitriy Lapshin [C# / .NET MVP]
          X-Unity Test Studio

          Bring the power of unit testing to VS .NET IDE

          "William Stacey" <staceyw@mvps.o rg> wrote in message
          news:up$bhz6cDH A.1772@TK2MSFTN GP10.phx.gbl...[color=blue][color=green]
          > > Did you actually read my message (I mentioned nunit)? My problem is how[/color][/color]
          to[color=blue][color=green]
          > > add test cases to windows forms controls (custom controls of my design)[/color][/color]
          in[color=blue]
          > a[color=green]
          > > useful way.[/color]
          >
          > Sorry Pete, I must have only thought I read your post. My mistake.
          >[color=green]
          > > All the unit testing frameworks (for c#) work in virtually the same way.
          > > NUnit is not unique, or even necessarily the best. Coupled with the fact
          > > that their website seems to completely lack any info on typical/advanced
          > > usage patterns, that link is not too useful to me.[/color]
          >
          > Well it can still be usefull. A form is just a class right. You can't[/color]
          test[color=blue]
          > the visual look of the form easily, but you can test its function. You[/color]
          can[color=blue]
          > create an instance of a form, plug in test data or set control values, hit
          > buttons and read results from text boxes, etc. So you can test form
          > function and exceptions, and if things are visable or other properties on
          > the form/controls, etc.
          > --
          > wjs
          >
          >[/color]

          Comment

          • Pete

            #6
            Re: Unit testing

            Hi,

            Arild Fines wrote:[color=blue]
            > The general idea is to put as little actual functionality in the GUI
            > layer as possible. Instead factor out the "meat" of the application
            > into separate classes which have no knowledge of the GUI layer. These
            > classes can then be tested using a unit testing framework.[/color]

            Hmm.. I've started using fxcop (which noone pointed out) and it works quite
            well. As for unit test, the benefits here seem dwarfed by the effort
            involved (my controls are mostly visual, certainly not enough "meat" to
            warrant a separate class) so I think I'll pass.

            -- Pete


            Comment

            Working...