Learning Jasmine and NUnit
Jasmine website :
Jasmine documentation :
jQuery matchers
Jasmine plugin :
To install jasmine at Global level :
npm install -g jasmine
Unit Test :- A unit test is a function which calls another function (unit) and checks the correctness of the outcome from the called function.
Integration Testing :- Integration testing is testing a unit of work without having full control over all of it and using one or more of its real dependencies, such as time, network, database, threads etc.
Unit Testing Framework :
- MSTest :- Unit testing C# with MSTest
- NUnit :- Unit testing C# with NUnit
- xUnit.NET :- Unit testing C# with xUnit
Benefits of writing Unit Testing :-
- You are sure that code under test work correctly.
- Protection from bad changes
- True documentation of how system works.
- More productive development team
- Complex systems covered by unit tests are easier to understand
- Fewer defects in production
- Reduced business costs
Here goes NUnit
In NUnit, we have two attributes to know what to run.
[TestFixture]
The [TestFixture] attribute denotes a class that holds automated NUnit tests.
[Test]
The [Test] attribute can be put on a method to denote it as an automated test to be invoked.
[TestFixture]
public class unitTestDemo
{
[Test]
public void methodOneTest()
{
}
}
Note. : - In NUnit, methods is going to be void which doesn't accept any parameters.
Assert.That<T>(T actual, IResolveConstraint expression);
Major Logical Constraints :
- Is
- Has
- Does
2nd Level Constraints :
- All
- Not
- Some
SetUp and TearDown : SetUp and TearDown are attributes in TextFixture and used for initialisation and destruction. SetUp attribute is used to maintain clean code in test class and by doing so we can avoid writing repeatable line of codes (common variables and objects) in the test methods. If there is an unmanaged resources which is responsible for memory leak and need to be cleaned before we run next unit test.
namespace ProjectABC.Test.SetupMethod
{
[TextFixture]
class myTests
{
private my _my;
[SetUp]
public void SetUp()
{
_my = new my();
}
[TearDown]
public void TearDown()
{
_my.Dispose();
_my = null;
}
[Test]
public void TestMethod1()
{
Assert.That(_my.PageExit, Is.True);
}
[Test]
public void TestMethod2()
{
Assert.IsTrue(_my.ButtonDisabled);
}
SetUp method is going to be called before running any unit test method i.e. initialise first then run unit test method and TearDown method is going to be called after each unit test method i.e. clean any unmanaged resources before running the next unit test method.
Parameterized Tests
Types of Tests :
- Unit Tests - Verify the behaviour of a unit under test in isolation.
- Integration Tests - Verify the behaviour of either a part of a system or a whole system
- Acceptance Tests - Verify the software from user's point of view
Integration tests generally run slower than unit tests, which usually happen in memory, so the fast-running tests are usually unit tests and the slow-running tests are usually integration tests.
Tools to create automated build systems :
- CruiseControl.NET (cruisecontrol.sourceforge.net)
- TeamCity (JetBrains.com)
- NAnt (nant.sourceforge.net)
- MSBuild (http://msdn.microsoft.com/en-us/library/wea2sca5(VS.80).aspx)
- FinalBuilder (www.FinalBuilder.com)
- Visual Build Pro (www.kinook.com)
- Visual Studio Team Foundation Server (http://msdn.microsoft.com/en-us/teamsystem/default.aspx)
Resources :
Happy Learning...