Re: Test Driven Development and C#

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Deckarep <deckarep@xxxxxxxxx> wrote:
I actually have two seperate questions regarding Unit Testing with
NUnit in C#. Please keep in mind that I'm new to the concept of Unit
Testing and just barely coming around to feeling comfortable writing
tests first and code after as in TDD style.

Question 1:

How can you effectively start incorporating Unit Testing in your
average day when you are the only one doing it on a team? For example,
a team of 12 programms work on 1 Solution. Potentially any programmer
could jump around to editing another programmers code. So if I write
'Class A' from the start using TDD methods. I will have my Class and
it's Unit Tests complete. Then I move onto something else. Another
programmer comes along and needs to edit what I wrote and breaks my
Unit Tests. In fact, they don't even bother to run or update the Unit
Tests so when I come back to Class A and realize all or some of the
Unit Tests are broken I have to spend much time trying to fix them and
figure out what's wrong.

That's always a problem. Continuous integration could help here - run a
build and the unit tests really regularly, so you can find out as soon
as the unit tests are broken and politely ask the developer responsible
to fix them.

So given this scenario is safe to assume that you simply can't do TDD
or Unit Testing as a technique until the whole team is ready to develop
in this fashion? I would like to add this development technique to my
skillset but without other developers convinced that this trend is
effective and proven I don't see them adhering to this anytime soon so
does that mean I'm screwed?

It does make it a *lot* harder, certainly. I find that when you can
point out bugs that the other developer has introduced by showing
failing unit tests, that goes a fair way to convincing them. Of course,
if you can also show them that *your* bug count is relatively low, that
helps a lot too :)

Question 2:

How does one go about Unit Testing data structures like XML that are
expected to change frequently? XML is an effective way to have a
data-structure easily change over time and it's nature is very fluid.
So how can you write Unit Tests against validating XML when it's
structure changes so frequently? When I say validate I don't mean
validate if it's well-formed XML. I simply mean validating it's
contents.

Well, validate what's important - and write your tests in a way which
make them easy to change. In particular, use data driven tests - if you
can easily express the start point and end result in terms of data (eg
XML files) then it's often quite easy to come up with a battery of
tests very quickly and change them when you need to. It doesn't always
work though - sometimes you'll need to make a trade-off between one
file which a lot of the tests use, which means potentially changing a
lot of tests if something changes, or using one file per test, each
only covering a very small portion of the data domain, and ending up
with a lot of duplication.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: Test Driven Development and C#
    ... it's Unit Tests complete. ... programmer comes along and needs to edit what I wrote and breaks my ... So how can you write Unit Tests against validating XML when it's ... validate if it's well-formed XML. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: standalone validating XML parser for Solaris?
    ... the unix command line to validate large XML files against an XML DTD. ... Older versions only parse but dont validate. ... More recent versions can validate against DTD or Schema. ...
    (comp.text.xml)
  • Re: How important is validation?
    ... As a software developer, you know that the task is not completed ... you only have to view the page with one browser on one ... > designed to validate in 2000 would still validate today. ... should validate today for its version of HTML. ...
    (comp.infosystems.www.authoring.html)
  • Re: Adobe Flex for MV GUI
    ... I really don't like the trend toward using XML in-line with code to ... as long as its readable and the developer has access to tweak ... free/open-source Ajax Control Toolkit which most ASP.NET ... Your HyperFlex control could easily be a common addon for any Flex ...
    (comp.databases.pick)
  • Re: problems with loading different xsds with same namespace to XmlSchemaCollection
    ... What I am trying to achieve is being able to validate a XML document ... own types and elements that extend base types from the Base XSD. ... That helps my application to load in additional to the base XSD a group ...
    (microsoft.public.dotnet.xml)