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;
}
}
}