Skip to Content
Get my Updated Resume

16 mins read


Test Driven Development and Its frameworks comparison

In this article we'll see about what is testing in SOftware Development, why it is important in SOftware Development Journey.


In Software development, the software is developed using multiple methods of Software Development, naming some of them :

  • Waterfall method
  • Rapid Application Development
  • Agile Method
  • DevOps

Using these methods quality software can be developed but there is always a probability of Errors and Bugs, which makes Software Testing a necessary part of the Software Development Process.

Software Testing

Software Testing is a process of checking if the actual product can give the expected requirements to make sure that the product is Bug-Free.

Software Testing makes sure that all the gaps between the expected outcome and the actual outcome of the product are met by using tools that require manual or Automated tools to check and evaluate.

Benefits of Software Testing

Software Testing is helpful to Developers and the investors of the product in the ways mentioned below

  • Increased Security: Testing an App before releasing it to the public makes sure that the Product is more reliable when exposed to the Internet, people trust Products that are reliable and safe to use.
  • Cost Effective:- Testing a Product can help a Developer or a Business to resolve many problems which they can face later can be resolved beforehand only as when it's released to the public it will only make the users less userfriendly.
  • Product Quality:- Testing a Product before exposing it to the public can help in increasing the quality of the product by making it more robust and reliable.

Types of Software Testing

Many types of testing can help a Product evolve and grow over time. We generally consider 3 types of Testing to be more important than others

  • Unit Testing This software testing basic approach is followed by the programmer to test the unit of the program. It helps developers to know whether the individual unit of the code is working properly or not.
  • Integration testing It focuses on the construction and design of the software. You need to see whether the integrated units are working without errors or not.
  • System testing In this method, your software is compiled as a whole and then tested as a whole. This testing strategy checks functionality, security, and portability, amongst others.

Styles of Software Testing

There are Two Styles of Software Testing

  • Behaviour-Driven Development This type of Testing and Development is an Agile Software Development process that encourages collaboration among developers, quality assurance experts, and customer representatives in a software project. It encourages a team to use concrete examples of how the software works or how shall it behaves.

  • Test-Driven Development It is a type of Development in which tests are written before the Product is even developed, which leads a Developer to write clean, minimal, optimized code to produce the expected output only.

Test-Driven Development

Test Driven Development is a type of Development that make sure that the Test for the Product's Functions, Units, and others are written before the Product is even Developed.

It means that the test at the first Iteration has to fail and then after Writing the correct and suitable code it will successfully execute.

Steps for Writing General Test-Driven Development

  • Add a Test Write the test, before writing the test for the product a Developer must know all the requirements of the Product that the user demands.
  • Run all the test cases Make sure that all the Test cases fail at the first and initial execution.
  • Write the Code Develop the logic for the actual development of the Product.
  • Run the Tests again Make sure all the tests are successful gets executed.
  • Refactor Code Now as the tests are passed and the code has been written refactor the code and make sure the code is readable and optimized keeping in mind the performance of the Product.

Test Driven Development's test can be written in 3 steps:

  • Arrange Get all the elements of the Product in your Test and make sure everything gets loaded
  • Act Operate on the Elements as expected
  • Assert Expect the Product to give you the required outcome which can be the obvious answer.

Frameworks for Test-Driven Development

Jasmine ( Testing Tool for BDD )

Jasmine is a Testing framework that helps a Developer to build and Test JavaScript Projects, It doesn't rely on DOM( Document Object Model ), browser, or any other JavaScript frameworks. This Framework is only suitable for Projects which can execute JavaScript or Node. js-based Projects.

It can also perform Client-side testing if the Project demands Client-side testing along with Server Side Testing.

It also comes with matches and is capable of developing your Matchers too.

  • Jasmine Query - It provides us matches for jQuery Objects, which is the easiest way for HTML Fixtures to test with.

  • Angular JS matches - It works well with Angular Js based Projects as it provides matches for working with Angular JS.

Advantages of working with Jasmine

  • Testing Projects based on Node.js or JavaScript projects With working with Jasmine a Developer can easily test JavaScript-based Projects or Projects based on node.js.

  • Writing Specs in CoffeeScript CoffeeScript allows the Project to not require a complete browser Instance to test the module, with the ability to require instant feedback.

  • Async Testing Support Jasmine allows the Developers to build a CallFake() function to call the function call at the end of the function and complete the test by returning done.

Disadvantages of working with Jasmine

  • Jasmine requires huge configurations, it requires an assertation library or mocking framework to work with it. If your project demands high configuration then it's the best choice else the process of configuration will become a problematic situation.

  • With the Introduction of Jest, the popularity of Jasmine has heavily declined with the use of developers.

Can Jasmine be considered the best Testing framework for JavaScript projects??

If your project is very huge and requires high configuration then yes, else the configuration only becomes a hurdle and after the Introduction of Jest, the same results can be obtained with a small amount of effort ( for small-scale projects ).

Sample Jasmine Testing Code for MthUtil.js

MathUtil.js

MathUtils = function () {};
 
MathUtils.prototype.sum = function (number1, number2) {
  return number1 + number2;
};
 
MathUtils.prototype.substract = function (number1, number2) {
  return number1 - number2;
};
 
MathUtils.prototype.multiply = function (number1, number2) {
  return number1 * number2;
};
 
MathUtils.prototype.divide = function (number1, number2) {
  return number1 / number2;
};
 
MathUtils.prototype.average = function (number1, number2) {
  return (number1 + number2) / 2;
};
 
MathUtils.prototype.factorial = function (number) {
  if (number < 0) {
    throw new Error("There is no factorial for negative numbers");
  } else if (number == 1 || number == 0) {
    return 1;
  } else {
    return number * this.factorial(number - 1);
  }
};

MathUtil.test.js

describe("MathUtils", function () {
  var calc;
 
  //This will be called before running each spec
  beforeEach(function () {
    calc = new MathUtils();
  });
 
  describe("when calc is used to peform basic math operations", function () {
    //Spec for sum operation
    it("should be able to calculate sum of 3 and 5", function () {
      expect(calc.sum(3, 5)).toEqual(8);
    });
 
    //Spec for multiply operation
    it("should be able to multiply 10 and 40", function () {
      expect(calc.multiply(10, 40)).toEqual(400);
    });
 
    //Spec for factorial operation for positive number
    it("should be able to calculate factorial of 9", function () {
      expect(calc.factorial(9)).toEqual(362880);
    });
 
    //Spec for factorial operation for a negative number
    it("should be able to throw error in factorial operation when the number is negative", function () {
      expect(function () {
        calc.factorial(-7);
      }).toThrowError(Error);
    });
  });
});

Karma ( Testing Tool for TDD ( majorly used for Angular JS Projects ) )

Karma is an Open Source utility that allows a Developer to fire up multiple instances of Browsers and run tests in those browsers. Tests are then examined and the results are displayed to the Developer of which tests passed or failed in which of the browsers connected to it.

Karma Plugins

Advantages of Karma

Karma has great advantages over the other frameworks used for Testing in TDD architecture.

  • Integrations with popular CI/CD frameworks Integrations and configurations of Karma can be done easily, also Karma can easily integrate with the most popular CI/CD tools available to the public like Jenkins CI server, Travis, Semaphore, and others with its plugin support.

  • Cross-Device and Cross-Platforms As we already know that Karma instantiates multiple Browser instances which can be of different sizes, it can also help us to mimic popular platforms like Android, IOS, Desktop, and Android TV.

  • A Popular list of available plugins Just like Jasmin, Karma has a vast list of available plugins which we can integrate and customize as the project demands.

Disadvantages of Karma Testing

  • Those files will be your actual js files; you will tell karma how to load them. If you use require, there is a karma plugin, and some config is needed.

Sample Code for Karma Testing

describe("AngularJSController", function () {
  beforeEach(module("sampleApp"));
 
  var $controller;
 
  beforeEach(inject(function (_$controller_) {
    $controller = _$controller_;
  }));
 
  describe("$scope.ID", function () {
    it("Check the scope object", function () {
      var $scope = {};
      var controller = $controller("AngularJSController", { $scope: $scope });
      expect($scope.ID).toEqual(5);
    });
  });
});

Karma Testing is performed on Angular JS-based projects and it is well suited to them only.

==Jasmine and Karma==

The best thing you can do with Projects based on JavaScript Code is you can use both Jasmine and Karma side by side, it'll give a performance boost with maximum security to a Product.

Karma and Jasmine

Flutter Testing

Flutter is a Framework Developed by Google back in 2018 for the development of Cross Platform App Development, with Flutter a Test Driven Development process was also released to develop Apps with Flutter.

Flutter has 3 categories of Testing:

  • Widget Testing      Widget tests are used to test a single widget of a Flutter application. Widget tests are written using the WidgetTester class. To write a widget test, you first need to create a file with a .dart extension. In this file, you will need to import the package: Flutter_test/Flutter_test.dart package.
  • Unit Testing      These tests focus on individual units of code, such as classes and methods. Unit tests are typically written by developers. Unit tests are used to test individual units of code, such as classes and methods. Unit tests are written by developers and help to ensure that the code is working correctly. To write a unit test, you first need to create a unit test file. This file contains the tests that will be run on the code. The file should have a .dart extension.
  • Integration testing      Integration tests are used to test the entire Flutter application. System tests are written using the package:integration_test package. To write an integration test, you first need to create a file with a .dart extension. In this file, you will need to import the package:integration_test/integration_test. dart package and your test app’s main function

Advantages of Flutter Testing

  • Cross-Platform Development Flutter can help you build Apps for multiple platforms just by coding on one platform, being strictly typed language can give a boost in performance, which means writing tests for one platform can benefit you to write tests for multiple platforms.

Disadvantages of Flutter Testing

  • Flutter Tests are Slow Flutter tests can be slow in time, it is not because of anything else but because you've written the code unoptimized.

  • Flutter Tests are failing If the Tests are failing try rectifying your code or writing the Logic for the Product in a better way.

Advanced Techniques to test a Flutter App

There are a few techniques that can be considered Advance Techniques and are suitable for Testing React Applications:

  • Mockito Mocito is a package that can help a Developer to mock an API request and act on the basis of inputs given.

  • Profiling It is a technique that can be used to identify performance bottlenecks in an application. Profiling can be done using Apple's Instruments tool on iOS, or the Android Profiler tool on Android.

Sample Test Written in Flutter for an App

import 'package: test/test.dart';
 
void main() {
  group('Notes Cubit', () {
    test('default is empty', () {
      var cubit = NotesCubit();
      expect(cubit.state.notes, []);
    });
 
    test('add notes', () {
      var title = 'title';
      var body = 'body';
      var cubit = NotesCubit();
      cubit.createNote(title, body);
      expect(cubit.state.notes.length, 1);
      expect(cubit.state.notes.first, Note(1, title, body));
    });
 
    test('delete notes', () {
      var cubit = NotesCubit();
      cubit.createNote('title', 'body');
      cubit.createNote('another title', 'another body');
      cubit.deleteNote(1);
      expect(cubit.state.notes.length, 1);
      expect(cubit.state.notes.first.id, 2);
    });
 
    test('update notes', () {
      var cubit = NotesCubit();
      cubit.createNote('title', 'body');
      cubit.createNote('another title', 'another body');
      cubit.createNote('yet another title', 'yet another body');
 
      var newTitle = 'my cool note';
      var newBody = 'my cool note body';
      cubit.updateNote(2, newTitle, newBody);
      expect(cubit.state.notes.length, 3);
      expect(cubit.state.notes[1], Note(2, newTitle, newBody));
    });
  });
}
Is Flutter preferred for Mobile App Development??

Flutter is developed in such a way that it can be shipped on multiple platforms like Linux, Mac, Windows, Android, and IOS. Any Developer can prefer flutter for any kind of Development, it is widely used for App Development in Android, but we can also see in the Latest Version of Ubuntu uses Apps built on top of Flutter.

React Testing

React is a popular Framework for FrontEnd App Development, which helps developers to develop high-quality Web Apps with even more complex UI.

With the help of React, we can also develop Apps for Multiple Platforms with the help of React Native, whose motive aligns with FLutter itself of developing Cross-platform Apps just by writing code once.

React Testing is a Utility/package made available by the React team itself to use to test React Apps more suitably and easily. We can also opt for using Jest and Cypress to gain the same output with even better performance.

React Testing is mostly used with a toolkit such as RTL ( React Testing Library ) + Jest + JSDOM**_.

Sample COde for React Testing Library

// additionCalculator.test.js
 
const additionCalculator = require("./additionCalculator");
 
describe("additionCalculator's test cases", () => {
  test("addition of 4 and 6 to equal 10", () => {
    expect(additionCalculator(4, 6)).toBe(10);
  });
 
  test("addition of 100, 50, 20, 45 and 30 to equal 245", () => {
    expect(additionCalculator(100, 50, 20, 45, 30)).toBe(245);
  });
 
  test("addition of 7 to equal 7", () => {
    expect(additionCalculator(7)).toBe(7);
  });
 
  test("addition of no argument provided to equal 0", () => {
    expect(additionCalculator()).toBe(0);
  });
});