开发者

Is NUnit worth learning? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed last year.

开发者_如何学Go Improve this question

I am a college student that makes his programs here and there in C#, mostly scientific simulations. Is there any use in learning NUnit?

I keep hearing people talking about it but I don't fully grasp what it is in the first place. Is it something that every programmer should use, or something that is more suited for big projects with lots of people?


Testing is a vital part of writing software - any kind of software. Whether you are writing a little routine to sort numbers, or a system to launch space ships to Mars.

Now it used to be that developers would write their code, and then exercise it by hand - often in a debugger - to verify that it did what they expected. This was a painful and tedious way to test their code. Not only was it tedious and painful - but it wasn't repeatable. This meant that every time you made a change you had to manually repeat the tests and hope you didn't forget anything or do things slightly differently. Quality suffered - and there was much sorrow and weeping.

Eventually, developers realized that they could write a separate program that would exercise their code by running it through the conditions that they expected it to handle, and having that code verify the results. Things started to get better. This approach to testing was often called a test harness.

Writing test harnesses helped, but there was a lot of repetitive code - there is quite a bit of infrastructure related to running and verifying tests. However, some really smart developers out their said: "We're not going to write boiler plate code over and over ... we'll make a library to do it for us." And so unit testing tools like JUnit and NUnit (and many others) were born.

These libraries (and tools) help you structure, organize, and execute your tests. They provide convenient methods to verify conditions, trap and trace exceptions, and report which tests passed and which ones failed. Finally, developers could focus on the important part: writing the tests and verification logic that would help assure that the code they wrote worked. These tests were repeatable. They could be run as part of an automated build process. They could be handed down through the generations and added to by others as new failure points were found and fixed. They could be re-run by the original developer months and years after the original code had been written to make sure things still work.

If you plan to be a successful software developer at any level, in any size organization (even if it's just yourself) - you should learn about - and embrace unit testing.

Here are some resources to help you on your way:

  • NUnit Documentation and Samples
  • The Art of Unit Testing
  • Unit Testing Best Practices
  • Write Maintainable Unit Tests That Will Save You Time And Tears


Yes you should use it. (or any test runner)

Testing is quite an important part of programming (In my opinion), so if you (or someone else) changes a part of code, and it happens to break something down the line, your tests should pick this up.

Well, that's how I see it, I'm still new to unit testing.

An Example.

Lets say I have a method

Add(int a, int b)
{
  return a + b;
}

My Unit Test would be:

[Test]
public void Test001_TestAdd()
{
    Assert.IsTrue(Add(1,3) == 4);
}

If someone changed the Add Method to lets say:

Add(int a, int b)
{
  return a * b;
}

My Unit test would fail, and could potentially save a life (if you work in medical software, or for NASA), or stop a potential bug :)

Now if they had Unit Tests, this may not have happened, simple problem, missed.


Absolutely. Unit testing is one of the most important concepts to learn in modern software development.

It doesn't matter if your programs are scientific simulations, enterprise applications, etc. neither if you are in a big team or if you code alone (but in big teams is as important as compiling your code).

A good book to start on unit testing (for .net) is Pragmatic Unit Testing in C# with NUnit


Every programmer should learn it. Now, will every programmer use it? Likely not, but they should know it anyway.

Unit testing is very, very common nowadays, and understanding how it works is essential in any project other than the little hobby ones you're writing right now. Use the time you have now and get ready for your future. Also learn about Mock objects (related).


Unit testing has many values, depending on what you do and what projects you work on different parts of unit testing will be important to you.

At very least you should learn the basics of unit testing to have a fully rounded sense of the development process. As time goes on and you work on larger projects you will find that unit testing is an integral part of maintaining and growing large codebases.


NUnit is an excellent tool if you're interested in Test-Driven Development.

See my answer here for some notes about TDD.

I've found that if you can get a ReSharper license (Visual Studio plug-in that does many things) that the running of unit tests becomes so quick and easy that writing them really does become a no-brainer, even for small pieces of work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜