473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Test Driven Development and C#

Hello Group,

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.

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?

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.

I know these are long questions and I hope the C# group has a few
answers for me as I believe both of these topics to be relevant to this
group.

Thanks in advance,

-Ralph

Jan 16 '07 #1
9 2051
hi,

Deckarep wrote:
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.
I would bother, if the project doesn't compile. As far as i understand
the NUnit support for VS (i have only seen a demonstration), you can
control the severity of a failed unit test. Just don't let it compile.
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?
You need some rear cover. And prove as often you can, that tested code
is superior to untested code.
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.
DTDs or XML schematas describe the data structure not only the outline
of a XML document. Just validate your XML against a DTD or XML schema.
mfG
--stefan <--
Jan 16 '07 #2
Question 1:

Unit tests are aimed at atomic components and expect a certain
behavoir. If someone (including you) has modified the tested components
in such a way that they break the unit test, well, that's one of the
major points of unit testing (aside from TDD). You shouldn't have to
"spend much time trying to fix them and figure out what's wrong" since
you know exactly which test broke and why (eg component isn't returning
an expected value). If you are spending too much time then your
component isn't atomic enough and needs to be refactored anyway.

Question 2:

You shouldn't be unit testing the data structures. You should be unit
testing the components that deal with the data structures.

Deckarep wrote:
Hello Group,

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.

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?

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.

I know these are long questions and I hope the C# group has a few
answers for me as I believe both of these topics to be relevant to this
group.

Thanks in advance,

-Ralph
Jan 16 '07 #3
Deckarep <de******@gmail.comwrote:
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 - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 16 '07 #4
In NUnit, there is a way to add build events that flag failed tests. You can
try that approach, which would force the developer checking in code to fix
the unit tests. That won't get you any friends though. And you need friends
to survive.

I hate unit tests with a passion. It makes me a huge hyprocrite because i
have to teach nunit courses once per quarter (and sell it convincingly). But
it does have its merits and there is benefit to it. Unfortunately, by the
time developers learn about unit tests, they are already hard wired to the
debugger. I've given up long ago.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc

"Deckarep" <de******@gmail.comwrote in message
news:11**********************@38g2000cwa.googlegro ups.com...
Hello Group,

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.

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?

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.

I know these are long questions and I hope the C# group has a few
answers for me as I believe both of these topics to be relevant to this
group.

Thanks in advance,

-Ralph

Jan 17 '07 #5
Many people have given good comments so i don't need to respond
directly. One piece of information I thought you might want though is
Microsoft's response to NUnit. The "Visual Studio Team Edition for
Software Developers" has the unit test stuff built in. It works nearly
like NUnit. It makes making unit test pretty easy. You can just right
click on a method and create a skeletal unit test. It can create a unit
test project if one does exist. Following is a link to where you can get
it for free if you have MSDN Developer version license. Sadly is doesn't
come on the DVDs.

http://msdn.microsoft.com/vstudio/te...v/default.aspx

Hope this helps.
Leon Lambert

Deckarep wrote:
Hello Group,

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.

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?

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.

I know these are long questions and I hope the C# group has a few
answers for me as I believe both of these topics to be relevant to this
group.

Thanks in advance,

-Ralph
Jan 17 '07 #6
While clicking on a method and generating a Unit Test from it is a nice
convenience isn't that a little backwards from what TDD should be?

I've been reading how important it is to write the test first...I don't
know...just a thought...perhaps I'm just being too picky.
Leon Lambert wrote:
Many people have given good comments so i don't need to respond
directly. One piece of information I thought you might want though is
Microsoft's response to NUnit. The "Visual Studio Team Edition for
Software Developers" has the unit test stuff built in. It works nearly
like NUnit. It makes making unit test pretty easy. You can just right
click on a method and create a skeletal unit test. It can create a unit
test project if one does exist. Following is a link to where you can get
it for free if you have MSDN Developer version license. Sadly is doesn't
come on the DVDs.

http://msdn.microsoft.com/vstudio/te...v/default.aspx

Hope this helps.
Leon Lambert

Deckarep wrote:
Hello Group,

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.

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?

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.

I know these are long questions and I hope the C# group has a few
answers for me as I believe both of these topics to be relevant to this
group.

Thanks in advance,

-Ralph
Jan 17 '07 #7
That is exactly what i do but we design the interfaces first. I really
can't conceive on how you could possibly design a test without defining
the interfaces first. My normal development process it to
1) Have a meeting with customer or customer surrogate and a test person
to get requirements and rough in the upper interfaces.
2) Generate skeletal unit tests with the test person based on
requirements and starting interfaces.
3) Generate abstract base classes to implement the interfaces. These are
generally to capture common functionality and to provide any needed
class factories.
4) Flesh in either abstract classes or derive some child classes to give
some very primitive functionality.

At this point i have enough to start an iterative pattern of development
that is supported by unit tests.

This works for me. I have no clue how you could jump in and write unit
tests without defining the interfaces.

Leon Lambert

Deckarep wrote:
While clicking on a method and generating a Unit Test from it is a nice
convenience isn't that a little backwards from what TDD should be?

I've been reading how important it is to write the test first...I don't
know...just a thought...perhaps I'm just being too picky.
Leon Lambert wrote:
>Many people have given good comments so i don't need to respond
directly. One piece of information I thought you might want though is
Microsoft's response to NUnit. The "Visual Studio Team Edition for
Software Developers" has the unit test stuff built in. It works nearly
like NUnit. It makes making unit test pretty easy. You can just right
click on a method and create a skeletal unit test. It can create a unit
test project if one does exist. Following is a link to where you can get
it for free if you have MSDN Developer version license. Sadly is doesn't
come on the DVDs.

http://msdn.microsoft.com/vstudio/te...v/default.aspx

Hope this helps.
Leon Lambert

Deckarep wrote:
>>Hello Group,

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.

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?

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.

I know these are long questions and I hope the C# group has a few
answers for me as I believe both of these topics to be relevant to this
group.

Thanks in advance,

-Ralph
Jan 18 '07 #8
Leon Lambert wrote:
That is exactly what i do but we design the interfaces first. I really
can't conceive on how you could possibly design a test without defining
the interfaces first.
You write the tests based on "What do I want to be able to do with this
interface?"

Write the code as if everything you want is there, and then add those
methods to the interface. It means that the design of the interface is
based on what you actually want to do with it, rather than what you
think you might want to expose - I find it improves my interface design
a lot.

That's the difference (IMO) between "test driven development" and "test
first development": test *first* development suggests you write the
tests before the production code. That's certainly good, but test
*driven* development (where the tests drive the design as well as the
implementation) is better IMO.

Jon

Jan 18 '07 #9
Question 1:
Once you start using unit tests, the others will see the benefits when your
code passes more often, has fewer bugs. Of course, this depends on having
standards. If the organization is lax, your efforts will only pay off for
you in the knowledge you are doing better.

Question 2:
With data structures, you stick with schema and setup data. You do not test
with prodution data ... ever. By sticking to schema and known data, you get
known results.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

********************************************
Think outside the box!
********************************************
"Deckarep" <de******@gmail.comwrote in message
news:11**********************@38g2000cwa.googlegro ups.com...
Hello Group,

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.

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?

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.

I know these are long questions and I hope the C# group has a few
answers for me as I believe both of these topics to be relevant to this
group.

Thanks in advance,

-Ralph
Jan 25 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
0
by: Tim Haughton | last post by:
I've just released an article on using Test Driven Development with C# and Windows Forms. GUI's are often difficult to test, so I thought it might be of interest. The article along with the...
3
by: Sasha | last post by:
Hi everybody, I am starting a new ASP.NET/SQL Server project and this time I want to do it through Test-Driven Development (TDD). The problem that I ran into is this: How do you test data access...
3
by: Yannick Tremblay | last post by:
Hi C peoples, I have been working with OO languages in recent years mostly C++ and Java and I have seen the advantages of good unit testing frameworks and/or test driven development. I've...
10
by: Michael B. Trausch | last post by:
Alright, I seem to be at a loss for what I am looking for, and I am not even really all that sure if it is possible or not. I found the 'pdb' debugger, but I was wondering if there was something...
2
by: Steven D'Aprano | last post by:
I'm working on some functions that, essentially, return randomly generated strings. Here's a basic example: def rstr(): """Return a random string based on a pseudo normally-distributed random...
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
6
by: Joel Hedlund | last post by:
Hi! I write, use and reuse a lot of small python programs for variuos purposes in my work. These use a growing number of utility modules that I'm continuously developing and adding to as new...
0
by: bhappy | last post by:
Hi All, I am doing a project in ASP.Net3.5, I needs to write test methods for my code. Please any one help me on how to use Test Driven Development(TDD) in my project? What are the softwares...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.