Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I start unit testing?

I know that unit testing is desirable, and I am interested in doing unit testing. The only problem is I have no idea how, or even where to start really. So my question is: How do I learn about and start unit testing? Specifically I frequently write Java code in NetBeans and C# code in Visual Studio and am interested in what tools to use and how to get my feet wet. Can anyone offer any advice for an absolute unit testing n00b?

I know that there are a lot of somewhat similar questions out there but I am less interested in why and more interested in how.

like image 340
ProgrammingPope Avatar asked Aug 19 '09 14:08

ProgrammingPope


People also ask

How do you introduce unit testing?

To perform unit testing, you have to test every output of your code unit with their expected return value to confirm if they adhere to their contract. Run your tests to confirm if your code unit is working as expected. Now, say you were to change the expected output of your test to a wrong value.

How can unit testing be done?

Unit tests can be performed manually or automated. Those employing a manual method may have an instinctual document made detailing each step in the process; however, automated testing is the more common method to unit tests. Automated approaches commonly use a testing framework to develop test cases.

How do I start JUnit?

Eclipse. To run from Eclipse, from your Package Explorer locate your JUnit test, in whichever folder you have designated it to. Right-click, and move down to Run As JUnit Test. This will execute your test and open a new JUnit window if not already open.

What should I do before unit testing?

In order to execute Unit Tests, developers write a section of code to test a specific function in software application. Developers can also isolate this function to test more rigorously which reveals unnecessary dependencies between function being tested and other units so the dependencies can be eliminated.


2 Answers

Try to read on StackOverflow, tag unit-testing :)

  • Is Unit Testing worth the effort?
  • How to make junior programmers write tests?
  • What is unit testing?
  • How do you know what to test when writing unit tests?

Another entry point would be the tags junit and nunit

There are lots of question dealing this.

If you're searching books about Unit Testing, try this thread: Good C# Unit testing book. There the famous Kent Beck book is mentioned, "Test Driven Development By Example".
It's worth reading!

Good luck!

like image 55
guerda Avatar answered Sep 24 '22 21:09

guerda


This Tutorial for writing JUnit tests in NetBeans should give you an idea how unit testing is done technically. NUnit for C# works pretty much the same.

For an advanced view of how to integrate unit testing into you daily development, the standard reference is Kent Beck's "Test Driven Development By Example". Here's a broad overview.

like image 29
Michael Borgwardt Avatar answered Sep 23 '22 21:09

Michael Borgwardt