Getting ready with cucumber

in #nodejs7 years ago

Hi friends,

If you followed previous posts, you should have a repository in git and you should at least perform basic git operations.


Topics

NTopic
1Getting git basics, create repository, configure globals,
get basic git knowledge in the most common commands.
- Creating a VM
- Topic #1 Git Basics
- Topic #1: Performing common tasks with git
-Learn BDD development using Cucumber.
-Run tests and verify results
-Setting up NPM for NodeJS dependencies.
-Setting up Sublime text editor with certain plugins and configuration
to suit your programming language needs.
-Start an Express application for web usage.
-Save data in MongoDB
-Get some MongoDB basic usage and queries.
-Apply styles to the web application.
-Deploy application in Heroku.
-Run tests and verify results

The most common project nowadays use the test driven development approach. In this post I will guide you through the basics of developing an app with cucumber. It is my first time using the JS flavor of cucumber so it is good practice for me and it will help you improve your skills as well. As I mention in the first course post my intention is to create an app with you that will help me transfer an amount to multiple users. We already talked about git lesson 1 and lesson 2.

To start setting up the test environment we will need to install a NodeJS package. I believe there is an upcoming post where I’ll explain a bit more about NPM, for now let’s just start the skeleton and later on we will be discussing each section of the app.

Type
npm init
This will ask for some details which are related with the app.
npm-init.png

It will generate a package.json file that we will be using to install the project dependencies.
Let’s proceed to install the only dependency that will be needing for now.
npm install cucumber --save-dev

package.png

It will add the cucumber package as a development dependency and it will update the package.json file.
install.png

install-result.png

Now we can run cucumber. You can see its help by adding -h at the end.
Selection_010.png

Now let’s create the cucumber structure. Usually we can find the features folder where the files represent logic being tested as well as live documentation. This is one of the best features in cucumber, we will be force to document all the requirements in a way that our clients or stakeholders can discuss them, improve them and in fact avoid mistakes because of poor communication or wrong requirements.

So let’s think about my idea. I want to send multiple users certain amount of SBD or STEEM.

What’s wrong with the idea?
Well I’m leaving out important parts, like I’m not specifying how will I send them the funds, if I need a form to fill for that or a plain file. In my head I can think of multiple options, but this is my idea and I’m acting as client/developer. In real life scenarios we will be writing someone else idea of how the app/software should do things. Maybe he wanted to read an email that contains a list of usernames to transfer funds, who knows?

That’s why it is important to write them down, share the document with the client and developers and help resolve any doubts that might pop up.

This is the feature example I wrote:
`
Feature: User can transfer to multiple accounts
If a user wants to transfer multiple accounts a certain amount can be done
by having a JSON file with all the usernames where the amount will go

Scenario: User can transfer an amount to multiple users
Given steemjs is loaded and configuration has been set up
When user attempts to send "0.001" of "SBD" to multiple accounts
Then transfers are done successfully
`
Selection_008.png

Now if we run it as it is now cucumber will generate some steps template in order to implement those.
Selection_011.png

Now let's create a support folder where the step definitions will be located. Let's create a step definitions file with the generated template and let's run the tests again.
Selection_013.png

Now let's add our files to the git repository.
Important: note that I added 'node_modules' to the .gitignore file so node modules are not added to the repository

Selection_015.png

I hope you are not disappointed for the progress we just made. I'll leave it as this for now because I do not want to overwhelm you with lots of knowledge and things to do. I prefer to have this short post so its easier to digest.

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 62014.91
ETH 2410.27
USDT 1.00
SBD 2.50