Review of an open source unit test tool- Cucumber_Word Doc

9
Created by Iqbal, Jabeen Shazia Review of Cucumber To begin with, In Software, the smallest testable part is called Unit, which has one or few inputs and mostly has single output. It is required to validate these units whether this each unit of the software performs as designed. This level of testing is referred as Unit Testing, where individual units/components of a software are tested [1]. The method used, to perform this unit testing is referred as White Box Testing. Usually, developers perform this unit testing, but in some cases it may be performed by the independent software testers as well. Unit tests are created and executed to make sure that the software performs as intended. The main purpose of this unit testing is to identify failures in the logic and/or algorithms that helps to improve the quality of the code. Motivation of Unit Test There are many motivations to perform the Unit Testing. Let me point out some of the motivations as follows. To change or maintain the code, we would need more confidence, which we will get by performing the Unit Testing to the units. In other words, whenever we have good unit tests and they run every time, any code is possible to modify Codes are often reusable. So to make use of the code, Unit testing is required to perform in those codes, in order to reuse the codes for other software. To make the development of the software fast, Unit Testing is required. The reason is, if there is no unit testing involved, then the system or user acceptance alone would be included, in which the effort required to fix the defects will be tedious whereas the effort required to fix the defects in the unit testing is less comparative to the system or user acceptance test. 1

Transcript of Review of an open source unit test tool- Cucumber_Word Doc

Page 1: Review of an open source unit test tool- Cucumber_Word Doc

Created by Iqbal, Jabeen Shazia

Review of Cucumber

To begin with, In Software, the smallest testable part is called Unit, which has one or few inputs and mostly has single output. It is required to validate these units whether this each unit of the software performs as designed. This level of testing is referred as Unit Testing, where individual units/components of a software are tested [1]. The method used, to perform this unit testing is referred as White Box Testing. Usually, developers perform this unit testing, but in some cases it may be performed by the independent software testers as well. Unit tests are created and executed to make sure that the software performs as intended. The main purpose of this unit testing is to identify failures in the logic and/or algorithms that helps to improve the quality of the code.

Motivation of Unit Test

There are many motivations to perform the Unit Testing. Let me point out some of the motivations as follows.

To change or maintain the code, we would need more confidence, which we will get by performing the Unit Testing to the units. In other words, whenever we have good unit tests and they run every time, any code is possible to modify

Codes are often reusable. So to make use of the code, Unit testing is required to perform in those codes, in order to reuse the codes for other software.

To make the development of the software fast, Unit Testing is required. The reason is, if there is no unit testing involved, then the system or user acceptance alone would be included, in which the effort required to fix the defects will be tedious whereas the effort required to fix the defects in the unit testing is less comparative to the system or user acceptance test.

Here it comes the main thing to consider, Cost. The cost of fixing of the defects detected in the Unit Testing would be less comparative to the cost of fixing of defects detected in another test such as system or acceptance testing.

Most useful for this unit testing is that debugging becomes easy. When a Unit test fails, only the latest changes need to be debugged.

Code after performing the unit testing is more reliable.

Perform Unit Testing

As we all know, Unit Testing is the most important level of testing. Below are the steps, which we are required to be considered to perform the Unit Testing. 1.Create a Test Plan - Test Plan is the document, which has the information about how the test will be performed, things to be tested, roles, responsibilities, test environment, activities involved etc.

1

Page 2: Review of an open source unit test tool- Cucumber_Word Doc

2.Create Test Cases and Test Data - Test case and Test Data documents are prepared using the sample format the Organization is adopting. Test Cases document will involve information such as Test case description, expected result, actual result, pass/fail, etc… Test Data document will involve information such as the inputs required to be created for the specific function and condition, to perform the unit testing.

3.Write Test Scripts – If we going to automate the Test Cases, then writing Test Scripts may results in saving time that is requited for testing

4.Write the actual code- Code is developed in such a way that these test cases gets pass when executed.

5.Once the code is ready to execute the test cases – Execution of the Test Cases, written in the above 2nd step, will be performed on the written code.

6.Fix the bugs if any and re test the code - Result of the execution of code will be captured. If the no error pops up, the codes are ready to go. If not, alter the code in such a way to remove the error/bug occurred during execution. Once the code is updated, rerun the test cases on the updated code to validate whether the result turns out to be pass.

7.Repeat the test cycle until the “unit” is free of all bugs - Tester need to keep updating the code, if the error/bugs appears until there is no bugs in that specific module.

Procedure to use the Unit Test Tool – Cucumber

Before going in to the working of this unit test tool, let me give you the little introduction of this test tool.

I have taken the unit-testing tool for Ruby language. As par of the Ruby culture, testing is a firmly embedded in to it.

We would have probably come across the Test::Unit Unit Testing tool, which adopts the Test Driven Development (TDD) concept. As we are aware that the manual testing wont be possible to apply in this TDD since the regression testing is required to perform every time the code is developed for one feature/function and tested. Automation testing is must to make this TDD successful. If suppose, the requirement is not correct, if the testers and developers misunderstood the requirements then the issue arises, the automation scripts are required to be updated, which is time consuming and rework. Therefore, to avoid these issues, to make the testers and developers more comfortable with the requirements, that in turn gave rise to Behavior Driven Development (BDD). Cucumber is the unit testing too and it is BDD tool. Cucumber is the latest addition to the RSpec family of tools.

Gherkin, a small computer language, is the format for Cucumber Specifications. It is so simple that we do not have to write the program to use it. This allow us to write it in English. Mostly, Product Owner in the scrum concept will write this gherkin scripts. This is used to build the test code. The main purpose to build this scripts is to confirm the requirement. Below is the example of simple Gherkin document:

2

Page 3: Review of an open source unit test tool- Cucumber_Word Doc

Feature: Password management Scenario: Forgot password Given a user with email "[email protected]" exists When I ask for a password reset Then an email with a password reset link should be sent

Bolded syntax - only keywords in Gherkins. Not Bolded – Normal English

Since I am crazy about Ruby programming language, I am using JetBrains RubyMine 2016.1.1 to perform this unit testing. There are two important files need to be created to make this unit testing successful.

1. The Gherkin script should be stored in a text file with the extension of .feature file. For our example, the file could be stored in a password_management.feature file.

2. The ruby code has to be written in the ruby file with the extension .rb where the code is written and validated against the gherkin. The file name should be step_definitions

When we run this gherkin script in JetBrians RubyMine, this cucumber will create a report to verify whether the software behaves exactly as mentioned in the Gherkin document or whether some codes are missing or incorrect.

To make this gherkin script to validate our code, we need to write some code, which translate the texts in this Gherkin document in to the language, the software understands it. In our case, we are using Ruby programming language. Cucumber looks for the matching words and executes that.

Repeat these steps until the result of the Gherkin scripts shows successful without any errors, which means the code written is 100 % ready to deliver to the user. This is reason practitioners are referring this cucumber unit testing tool as the acceptance testing.

Steps to play with cucumber

Step 01: Open the RubyMine JetBrains. Step 02: Create folder as “feature” and create two files

FilenameForGherkinScripts.feature Step_defination

Step 03: Write the Gherkin Scripts in the .feature file Step 04: Run the .feature file Step 05: Check the errors throwed Step 06: Paste the Gherkin Scripts and Write the actual Ruby Code in the Step definitions

file Step 07: Again run the .feature file, repeat the steps 05 and 07 until all errors the are

cleared out

3

Page 4: Review of an open source unit test tool- Cucumber_Word Doc

Figure 0.1 Flowchart of Cucumber

4

Page 5: Review of an open source unit test tool- Cucumber_Word Doc

GherkinScript

Step_definitions

5

Page 6: Review of an open source unit test tool- Cucumber_Word Doc

Step definitions – Final Code

Merits of Cucumber Unit Testing Tool

This unit testing tool is the friendly and understandable by non technical user

The Given-When-Then syntax of Cucumber scenarios imposes some structure on scenarios while leaving plenty of room for teams to grow their own language to describe their system

The style of writing test allows to reuse the gherkins scripts

Predictability and improve the confidence among testers and developers

The separation of the three level of feature in the gherkin scripts makes it easier to reuse any part of the code

As we know that interaction of Business and IT is not quite good. This cucumber makes the bond stronger between by mentioning the customer’s executable specification to the team, helping them to be aware of the business goals in mind at all times

Automation in cucumber lets the specification updated in the gherkins scripts

Automation leads to save the team from costly regression

Even the reuse of code is possible, since we write the features in separate

Supports other language as well beyond Ruby like Java, Scala, Groovy etc.6

Page 7: Review of an open source unit test tool- Cucumber_Word Doc

Quick and easy set up and executions Cucumber focuses on end-user experience Efficient tool for testing

Demerits of Cucumber Unit Testing Tool

Extra code for converting the textual specification to Ruby code

One more layer between test description and the code (you need to make sure the code really matches the description)

Cucumber supports only web environment

Summary and my insights

As I mentioned earlier, I am learning Ruby Programming Language now, so I wanted to select the unit testing tool for Ruby, I came across many tools such as JUnit, etc.. . These tools never really made me interested. Then I came across this ‘Cucumber’, which is Behavior Driven Development, made me excited and wanted to learn about it. I can say that this is most likely performing the acceptance testing in initial phase itself, where testing will be carried out, keeping customer in mind, how the application will behave for the customer. The most amazing thing about this cucumber is that, ‘Gherkins Scripts’, these scripts are non-technical, anyone can understand better, which makes everyone business analyst, testers, developers more comfortable. These scripts really increase the confidence in the code once it is developed and execute. Even though it has drawbacks such as extra task is involved for Gherkins Scripts, I feel like this approach is better than any tool I have researched.

Reference

[1] Unit Testing, http://softwaretestingfundamentals.com/unit-testing/[2] Steps to perform Unit Testing, http://www.exforsys.com/tutorials/testing/unit-testing.html[3] Cucumber, https://cucumber.io/#why[4] Procedure to perform cucumber and Pros/Cons, http://www.slideshare.net/selvanathankapilan/cucumber-gherkin-language[5] Step by step procedure, https://www.jetbrains.com/help/ruby/2016.1/creating-step-definition.html

7