Search This Blog

Thursday, 17 November 2022

Gherkins as BDD language

Gherkin is a plain-text language with a simple structure. It is designed to be easy to learn by non-programmers, yet structured enough to allow concise description of test scenarios and examples to illustrate business rules in most real-world domains.

Here is a sample Gherkin document:

Gherkin - Syntax

Feature: Account Holder withdraws cash
 
Scenario: Account has sufficient funds
    Given The account balance is 100
      And the card is valid
      And the machine contains enough money
     When the Account Holder requests 20
     Then the ATM should dispense 20
      And the account balance should be 80
      And the card should be returned

    Examples:                

InputExpected Output

balance = ₹100

card is valid

Atm has sufficient money > ₹20

ATM should dispense ₹20

Balance = ₹80

Card should be returned


It makes it easy for a team of technical and non-technical members to understand the requirement without confusion.

As a developer, you can now work on technically designing it into modules / classes, methods and properties.

This Feature Test Document (FTD) can be the output of a discussion with the client / market research team who provide requirements through examples.

Benefits:

  1. It is more clear than a requirement specification document in terms of expected inputs and outputs.
  2. This is a technical document which when given to a system can execute them as testcases.
  3. This document can be easily translated into an assertion language test case by a Unit-test developer
  4. It can be easily interpreted by Development, Testing, UI, Management team without any confusions

Unit Testing if an Event using NUnit

This is for Unit Test Developers, who write test cases for given features. Here we shall see how to unit test events, and internally how events work.

Events follow the pub-sub pattern. In this pattern, in .Net , internally a delegate is used to collect methods that subscribe to the event variable.

Let's take an example. If we consider the windows forms button control, it contains the click event.


The click event internally uses a delegate called Event Handler. The structure of the Event Handler delegate looks like this.



To attach a method to an event, we use the  '+=' operator.


Here we have used lambda expressions.


So how do we test such a scenario.

The strategy is simple. In the testcase, attach a dummy function to the event and then trigger it. By doing this we can assert if the event has occurred or not.


Hope this helps.

Thursday, 3 November 2022

Create and Execute React Js App

 

Pre-requisites:

                                Node Js (https://nodejs.org)

-----------------------------------------------------------------------------------------------------------------------------

1.      Create a react app

 

C:\Your_Directory\>create-react-app <app_name_in_lowercase> 

 

       OR

 

C:\Your_Directory\> npx create-react-app <app_name_in_lowercase>

 

               

        This will seed a react app for you. This react app consists of all dependencies and a project folder structure as shown in the screenshot below



a.       public: This folder contains all the files which can be shared with other files in this project such as images, json files etc

b.       src: This folder is used for react js components and code development

c.       node_modules: This works like the npm’s local registry

d.       The files like .gitignore, package-lock.json, package.json are configuration files

a.       .gitignore: This file contains all the files that should be ignored in case you wish to push your project to github

b.       .package-lock.json, package.json: These files store the dependencies for the react app. In case the node_modules folder is deleted, it can be recovered if package.json is available. The command used to recover node_modules from package.json is

>npm install

 

 

 

2.      Executing a react app

C:\Your_Directory\> > npm start

 

 

a.       This hosts the react app on localhost at port 3000 by default

b.       To pull down this hosted app press on the command prompt Ctrl+C