A step by Step learning NUnit (2)

Source: Internet
Author: User
Tags assert visual studio

In the previous chapter we briefly introduced NUnit's introductory example "Step by step NUnit (1)", so that everyone has a simple understanding of nunit.

The use of NUnit is very simple, but there are many best practices when it is used in a project. In this chapter we introduce some of the configurations and characteristics of the nunit that are not mentioned in the previous chapter.

To skillfully use nunit or to use and experience in practice, it is no use simply to learn knowledge points.

OK, no more nonsense. Continue the contents of the previous chapter.

In Visual Studio 2008, open the example in the previous chapter, the Calculator class has 4 simplest methods: Add, subtract, multiply, and divide. The four methods in the Calculatortest class are unit tests of the four methods of the Calculator class.

[Testfixture]

public class calculatortest ... 

{ 

[Test] public 

void Testadd () 

...        { 

Calculator cal = new Calculator (); 

int expected = 5; 

int actual = cal.        ADD (2, 3); 

Assert.AreEqual (expected, actual); 

[Test] public 

void Testminus () ... 

{ 

Calculator cal = new Calculator (); 

int expected = 5; 

int actual = cal.        Minus (5); 

Assert.AreEqual (expected, actual); 

[Test] public 

void testmultiply () ... 

{ 

Calculator cal = new Calculator (); 

int expected = 5; 

int actual = cal.        Multiply (1, 5); 

Assert.AreEqual (expected, actual); 

[Test] public 

void Testdivide () ... 

{ 

Calculator cal = new Calculator (); 

int expected = 5; 

int actual = cal.        Divide (5); 

Assert.AreEqual (expected, actual); 

} 

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.