Escolar Documentos
Profissional Documentos
Cultura Documentos
Question: In the NUnit test framework, which attribute must adorn a test class in order
for it to be picked up by the NUnit GUI?
It will be TestFixtureAttribute
The test fixture attribute is applied to a class that contains a suite of related test cases. If
an error occurs while initializing the fixture or if at least one of the test cases within the fixture
fails, then the fixture itself will be deemed to have failed. Otherwise the fixture will pass.
Output from the fixture, such as text written to the console, is captured by the framework and
will be included in the test report.
A test fixture has no timeout by default. This may be changed using the timeoutAttribute.
This attribute may be omitted whenever a test fixture class contains at least one test method
or test parameter or when other MbUnit attributes are applied to the test fixture class. This is
almost always the case unless for some reason you have an empty fixture.
The class must have a public default constructor. The class may not be static.
Definition
Features of NUnit
Assertions
Attributes
1. Assertions
Definition
Assertions are central to unit testing in any of the xUnit frameworks, and NUnit is no
exception. NUnit provides a rich set of assertions as static methods of the Assert class.
The most commonly used assertions.
• Equality Asserts
• Identity Asserts
• Comparison Asserts
• Type Asserts
• Condition tests
• Utility methods
• StringAssert
• CollectionAssert
• FileAssert
• Equal Constraint (Available NUnit 2.4)
• Same As Constraint (Available NUnit 2.4)
• Condition Constraints (Available NUnit 2.4)
• Comparison Constraints (Available NUnit 2.4)
• Type Constraints (Available NUnit 2.4)
• String Constraints (Available NUnit 2.4)
• Collection Constraints (Available NUnit 2.4)
• Compound Constraints (Available NUnit 2.4)
• Custom Constraints (Available NUnit 2.4)
2. Attributes
• Category
• Description
• ExpectedException
• Explicit
• Ignore
• Platform
• Property
• SetUp
• SetUpFixture
• Suite
• TearDown
• Test
• TestFixture
• TestFixtureSetUp
• TestFixtureTearDown
Getting Started with Nuint
Step 1
Step 3
Open your c# project and Create c# project then write a bussinessLogic in Class.cs file
For e.g.:
Create Invoice class for customer placing an order
Step 4
Step 5
[TestFixture]
i.e.
[TestFixture]
class TestNuint
{
}
Step 6
Create TestMethod to test businesslogic
i.e
public void TestInvoice()
{
}
Above this method Add attribute [Test]
i.e
[Test]
public void TestInvoice()
{
}
Step 7
Assign same values to both your expected result variable and objInvoice varibles
i.e
//Set Expected Result Variables
_CustomerName = "Shyam";
_ProductName = "L G Color TV";
_ProductCost = 22000;
_Quantity = 2;
_expectedTotalCost = _ProductCost * _Quantity;
_expectedProductDetails = _ProductName + " Cost of " + _ProductCost;
_expectedInvoice = _CustomerName + " For product " + _ProductName + " Quantity " +
_Quantity + " Total Cost " + _expectedTotalCost;
objInvoice.CustomerName = "Shyam";
objInvoice.ProductName = "L G Color TV";
objInvoice.ProductCost = 22000;
objInvoice.Quantity = 2;
_actualTotalCost = objInvoice.ProductCost * objInvoice.Quantity;
_actualProductDetails = objInvoice.DisplayProductDetails();
_actualInvoice = objInvoice.DisplayInvoice();
//add
Assert.AreEqual(_expectedInvoice, _actualInvoice);
Assert.AreEqual = It compares two objects makes special provisions so that numeric values
of different types compare as expected.
Step 8
i.e E:\nunit\Nuint2\Nuint2\bin\Release
Finally Click on Run Button to test your c# project
Test Result
Assert.AreEqual(_expectedInvoice, _actualInvoice);
Assert.AreEqual(_expectedInvoice, _actualInvoice);