Learning Jasmine and NUnit

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 :

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.

Constraint Model & Assertions

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 :




Resources :



Happy Learning...

To view or add a comment, sign in

More articles by Manish Kumar

  • Website to Learn From

    I have no TV Online library : Become an author for packtpub . Internet Radio : Fitness : Asteroid Database and Mining…

  • SOLID Principles and OOP Concepts

    SOLID Principles : S - Single Responsibility Principle O - Open Closed Principle L - Liskov Substitution Principle I -…

  • Web Development Part 2: Useful Learning Resources

    Understanding the Node.js event loop Bootstrap forms : Body parser : Functions : async.

  • Web development Part 1: Angular and Git

    Angular 1 : Released in October 2010 Angular 2 : Released in 2015 and is build using TypeScript. Features: Performance…

  • Understanding Webpack

    On npmjs website webpack package is described as "webpack is a module bundler. Its main purpose is to bundle JavaScript…

  • Base64 Encoder

    ASCII String : Manish ASCII Character Codes : m -109 and M - 077 077-097-110-105-115-104 8-bit Binary Character Codes :…

  • Angular Basics

    Angular is a JavaScript Framework which allows us to create reactive Single-Page-Applications ( SPA ). Angular…

  • Salesforce Lightning : Attribute

    In the lightning component, write below code: Here v = view, displayMessage is the name of attribute. <aura:component >…

  • Salesforce Lightning : Student Registration Form

    In the StudentRegistrationFormComponent.cmd component, write below code : <!-- StudentRegistrationFormComponent…

Explore content categories