In this chapter, we will create a hello world app which test our “helloworld.js” file. Before developing the hello world app, first refer the previous chapter and make sure that your environment is ready for testing using Jasmine.
Step 1 − Create a Web application in your IDE
To develop our hello world app in Jasmine we will use NetBeans8.1. In NetBeans, go to File → New Project → Html5/JS application and create a project. After creating the project, the project directory should appear as the following screenshot. We will give the project name as Jasmine_Demo.
Step 2 − Include the Jasmine lib file into the application
Once the demo project is created then you need to include the unzip folder from Jasmine library in the Unit Tests folder of the application created. After adding all the library files to our application folder, the structure of our project will appear as shown in the following screenshot.
Step 4 − Create a test case
Step 5 − Add reference to the output file
Our own file and the corresponding test case is successfully created which is to be tested . We had keed it under two different folders. Here, we will modify “SpecRunner.html” to include the reference of these two newly created file.
Step 6 − Execute by running SpecRunner.html
This is the last step in development of our application . Run SpecRunner.html in any of your favorite browser. Result will be same as shown in the following screen shot. The green screen indicates success, whereas red indicates failure in test case.
Step 7 − Understand the failure case
Till now we have observed the success test case of the hello world application. Now let us see failure test case. To implement a failure case we need to write a failure test case. For that, we are going to modify the helloworld.js file using the following code.
The above code will fail definitely because the output of our spec file is not getting the expected string helloworld(). The following screenshot of the specRunner.html file depicts that there is an error with its red indicator.
JasmineJS Related Interview Questions
|C++ Interview Questions||Adv Java Interview Questions|
|Core Java Interview Questions||Java Interview Questions|
|JavaMail API Interview Questions||Java collections framework Interview Questions|
|Java 8 Interview Questions||Computer Programming Interview Questions|
|Basic C Interview Questions||Java Hadoop Developer Interview Questions|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.