This blog will help you understand usage of Oracle Developer Cloud service for automated testing of NodeJS REST based web service application using a popular testing framework called Jasmine. The NodeJS application will be deployed on Oracle Application Container Cloud Service.

 

Note: For details on how to develop and deploy NodeJS REST application on Application Container Cloud using Developer Cloud service, please refer the blog link mentioned below.

https://community.oracle.com/community/cloud_computing/platform-as-a-service-paas/oracle-developer-cloud-service/blog/2016/09/07/oracle-developer-cloud-to-build-and-deploy-nodejs-rest-project-on-application-container-cloud

 

 

Tech Stack Usage

Eclipse: IDE for Nodejs development.

Expressjs: Nodejs module for REST web service development.

Grunt: Tool for building the Nodejs code archive for deployment.

Testing Framework: Jasmine

Oracle Developer Cloud: For managing the application lifecycle of the Project.

Oracle Application Container Cloud: For deployment of the Nodejs web service on container hosted by the cloud.

 

Setting up Jasmine for NodeJS application Testing:

After developing the NodeJS REST service application following the blog link given above, you will have a REST application in NodeJS deployed on Application Container Cloud Service. For this blog purpose I have named it as ServiceTest, but you are free to name it what you want.

 

The code files for testing using Jasmine framework can be included as part of separate ‘test’ folder(more from the segregation perspective). Since this is a sample service we are developing to see how the Jasmine based test automation works using DEVCS,we chose to keep the test scripts in the same application project. But for full scale projects, with comprehensive test scripts, you may choose to have a separate Git repository and project for the test scripts.

Below is the screen shot of the ServiceTest project in Eclipse:

 

2017-02-02 16_53_53-Node - Eclipse.png

Files for the NodeJS REST service:

 

  • Gruntfile.js – defines the build task
  • manifest.json - defines the main file to be executed, which is service.js
  • service.js – the actual service code is written here, it is the main service code which gets executed.
  • package.json – File to define the dependencies

 

Folder and files for test scripts:

Below screenshot describes the ‘test’ folder structure

2017-02-02 17_28_05-Node - ServiceTest_test_spec_helloTestSpec.js - Eclipse.png

For the purpose of clarity and maintainability all the file in the test folder are arranged in separate folders. Below is the description of what each file is for:

 

  1. jasmine.json -  it is the configuration file for Jasmine test framework.
  2. reporter.js – It contains script for testcase execution reporting and is a helper file so it resides in the  ‘helper’ folder.
  3. helloTestSpec – This file has the test case scripts or specs, as called in Jasmine.

 

Below is the link for detailed understanding of the Jasmine framework:

https://jasmine.github.io/2.0/node.html

 

There are specific configurations that need to be included for the test scripts to execute. Below are the file(s) and configurations highlighted:

package.json

The Jasmine config path is important as it is this configuration which tells the location of jasmine.json to the jasmine command which gets executed on execution of ‘npm test’ command. You will see this as part of the build configuration, later in the blog.

2017-02-02 17_34_57-Node - ServiceTest_package.json - Eclipse.png

 

A peek in to the test scripts code snippets:

jasmine.json

This file will contain the configuration for location of the spec file directory and also the helper files directory. Apart from these it would also contain the other Jasmine framework level configurations as well, as to be seen in the screenshot below.

2017-02-02 17_39_18-Node - ServiceTest_test_jasmine.json - Eclipse.png

helloTestSpec.js

This file contains the test case scripts or the ‘specs’ as known in the Jasmine framework terminology. It also would have to contain the application url to test. In case of deployment of the NodeJS application on Application Container Cloud, there is a specific anatomy of the application that is followed.

Here the application_name contains the name given in the deployment configuration of the Developer Cloud Service. While instance_url is the, url common to all the applications  deployed on Application Container cloud for the particular instance.

2017-02-02 17_38_57-Node - ServiceTest_test_spec_helloTestSpec.js - Eclipse.png

If you have already deployed the NodeJS REST application, then below screen shot shows, where you can look for the Url on the Application Container Cloud console.

2017-02-02 14_59_47-Oracle Application Container Cloud Details.png

reporter.js

I have just included a reporter helper for test case execution console reporting. We have configured certain properties as well to customize the report on console. You are free to include some other package for reports or write your own custom spec reporter as well.

2017-02-02 17_39_34-Node - ServiceTest_test_helpers_reporter.js - Eclipse.png

 

Build Configuration:

We will configure a separate build job in Developer Cloud Service for the test case execution. Below are the build job configuration screen shots.

2017-02-02 18_54_55-Build_ NodeTest - Oracle Developer Cloud Service.png

 

 

 

The Git repository remains the same as that of the NodeJS application as the ‘test’ folder is part of the NodeJS REST application project.

2017-02-02 18_55_14-Build_ NodeTest - Oracle Developer Cloud Service.png

 

 

We would have to change the directory to ServiceTest. Then install Jasmine using --save-dev jasmine, so that jasmine command is recognized as it get executed by npm test which in turn calls the test configuration in the package.json as described above in the blog and highlighted in the package.json screenshot.

2017-02-02 18_55_33-Build_ NodeTest - Oracle Developer Cloud Service.png

 

On Execution of the TestAppl build job:

On execution the test case/specs get executed and the console based report which can be seen from the build job console will show the test execution report. You can access the console output by clicking the console button in the build details.

2017-02-02 19_11_22-Build_ NodeTest - Oracle Developer Cloud Service.png

 

Below screen shot shows the console output on execution of the npm test, which in turn executes the jasmine specs. The report shows the tests executed, the response and the time taken to execute the spec. These configurations for display on console are part of the reporter.js helper script, described above in the blog.

2017-02-02 19_12_03-Build_ NodeTest - Oracle Developer Cloud Service.png

 

Enjoy automating your testing using Jasmine and seamlessly executing it using Oracle Developer Cloud Service.

 

**The views expressed in this post are my own and do not necessarily reflect the views of Oracle.