Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hi to all..
iam new to unit testing how to do unit testing..i tried some articles but i can't understand ..if any better articles are there pls let me know..
thanks in advance
Posted
Comments
Herman<T>.Instance 17-Aug-11 8:25am    
what have you read?

Following link might help you,

Test Driven Development Using NUnit in C#[^]

and following .NET Utility Library project has lots of Unit Testing,

.NET Utility Library[^]

:)
 
Share this answer
 
Have you ever heard of google? try this link:
http://en.wikipedia.org/wiki/Unit_testing[^]
 
Share this answer
 
Unit testing is not as simple as it seems...
You get various types of unit testing.
To mention a few:

DO-178B Level A -> Branch Coverage + Statement Coverage + Boolean Coverage (MCDC)
DO-178B Level B -> Branch Coverage + Statement Coverage
DO-178B Level D -> Statement Coverage Only

That is just from the DO-178B Standard
There are various standards around.

Requirements Testing is where you test your software requirements and afterwards check your coverage to see whether there are code in your software which doesn't link to a requirement. In the process testing whether the requirements do what they say they do.

A typical software requirement will read: "The function shall open the main form."
You wil typically set your input data (input parameters/or whatever), or setup your initial data to a closed main form, call the Unit Under Test (Function Under Test) and after the function executed, verify your input_data Vs you expected_data.

The field is wide and you get many different methods of testing.


Example:

Java
/* input/initial data */
Form obj = new Form();
obj.setVisible(false); // set to opposite as what we're expecting

/* Call unit under test */
EnableMainForm(obj);

/* Test Case Checks */
assert(obj.getVisible(), true);


Say that EnableMainForm had only one requirement but was doing a whole bunch of other things aswell not documented/linked to a requirement, your code coverage would show just that and you could log a bug for that reason.
 
Share this answer
 
Comments
_Zorro_ 17-Aug-11 11:52am    
Hi, just out of curiosity, aren't those "Software Considerations in Airborne Systems and Equipment Certification" as stated in wikipedia?

Are those standards applicable to general software applications?
R. Erasmus 17-Aug-11 11:56am    
Those particular standards are for Airborne Systems and Equipment but alot of their methologies gets used through-out the field. Thus what I'm saying is that, whether testing a aircraft system, banking system, or your little app, the method to go about is the same. The one is a bit more extensive than the other.
_Zorro_ 17-Aug-11 12:00pm    
That's really interesting since I suppose Airborne systems are carefully tested. I should dig into that.

Thanks!
R. Erasmus 17-Aug-11 12:12pm    
;-), its what I do.
Have a look a this stackoverflow thread:

What is unit testing

And here's a really small example:

Let's say you wrote a function that sums two Int32:

C#
Int32 Sum(Int32 int1, Int32 int2)
{
  return(int1 + int2);
}


You could unit test this function by creating a Unit Test project and create a function like this:

C#
[Test]    
public void Sum_Test
{
  Int32 result = yournamespace.yourclass.Sum(2, 3);      

  //2+3 = 5. So you want to make sure that YOUR function does the job right, hence the assert == 5.
  Assert.AreEqual(result, 5);
}


Unit test projects can be executed from Visual Studio or tfs builds, and probably from command line.

Now, what you should know is the difference between Unit Tests and Integration Tests, because most of the people are doing the second ones believing they are doing Unit testing.

Unit Testing

Integration Testing

You also should have a look into Mocking.

Mock Object

Once you get into it, I'd really recommend having a look at Pex and Moles:

Pex and Moles

Hope it helps
 
Share this answer
 
v2
Repeat this over and over again until it's the first thing you think of when you have a question like that.

"Google. Google. Google."
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900