Simplified nunit tutorial

Source: Internet
Author: User

It may be used.

 

Code
Using system;
Using nunit. Framework;

Namespace nunit
{
Class Program
{
Static void main (string [] ARGs)
{
}
}
[Testfixture] // The Declaration class contains a test
Public class testcalculator
{
// Public variables should be written outside to avoid repetition
Private calculator Cal;
Private int;
Private int B;
[Setup]
Protected void setup ()
{
A = 2;
B = 4;
Cal = new calculator ();
}
[Test]
Public void sumtest () // test method recommendation without Parameters
{
Assert. areequal (6, Cal. sum (a, B ));
}
[Test]
[Expectedexception (typeof (dividebyzeroexception)]
[Ignore ("not yet! ")] // Completely ignore; [explicit] can also be manually executed
Public void divtest ()
{
Int C = 0;
Cal. Div (a, c );
Assert. Fail ("got an expection! ");
}
// [Testfixturesetup] [testfixtureteardown] sharing and clearing expensive resources (db)
// [Suite] case and other suite containers (supporting cascading collection classes)
// [Category] is used for case classification. Include and exclude are used in cmd.
// Test the lifecycle contract:

}
// Obtain the class structure using reflection, and then use attribute to plan and test.
// The target class must be public and have default constructor (no side effects); otherwise, nunit cannot be identified or constructed.
Public class Calculator
{
Public int sum (int A, int B)
{
Return A + B;
}
Public int Div (int A, int B)
{
Return A/B;
}
}
}

 

 

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.