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.
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:
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
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:
- jasmine.json - it is the configuration file for Jasmine test framework.
- reporter.js – It contains script for testcase execution reporting and is a helper file so it resides in the ‘helper’ folder.
- 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:
There are specific configurations that need to be included for the test scripts to execute. Below are the file(s) and configurations highlighted:
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.
A peek in to the test scripts code snippets:
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.
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.
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.
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.
We will configure a separate build job in Developer Cloud Service for the test case execution. Below are the build job configuration screen shots.
The Git repository remains the same as that of the NodeJS application as the ‘test’ folder is part of the NodeJS REST application project.
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.
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.
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.
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.