User:Kpalani5/sandbox

= Functional Tests for Create Questionnaire Controller =

Expertiza
Expertiza is an open source peer review system developed by students and faculty at North Carolina State University. It allows students to form teams, submit assignments and review the work of their peers. In addition, it lets an instructor create new assignments, questionnaire for reviews and so on. It is built in Ruby on Rails platform.

Questionnaire System
Questionnaire is one of the most important components of peer review. It aids the instructor in assessing the reviews of a project, which in turn helps in grading. It lets the instructor create a set of questions(rubric) that needs to answered by students in order to complete their review. It also lets the instructor create a question advice that aids the reviewing process.

Problem Statement
We have been given the task of creating functional tests for the questionnaire creation function as currently, there are none.

In order to complete the task we will be using Capybara to write functional tests to
 * Create new questionnaire.
 * Create/Edit/Delete different types of questions.
 * Create/Edit question advice for criterion and scale questions
 * Create multiple tests to check valid and invalid cases.

Functional Tests
Functional tests are tests which ensure that the functionalities of a software system, as specified in a design or requirements document, are working as expected. Functional tests do not test a function or a method within a class but rather the functionality of the entire system. There are many frameworks that perform functional tests in Ruby. One such framework is Capybara.

Capybara
Capybara is framework, written in Ruby, that lets developers test their web application through simulations. It can be integrated with Selenium and Webkit.

Approach
Before writing code, we decided to build the different workflows of the system. A workflow is a sequence of steps a user would follow, within the web application, in order to complete a desired task/function of the system. Understanding the different workflows helped us write comprehensive test cases for various functionalities within the questionnaire system. Below is one such workflow.

There are 10 types of questions.
 * 1) Login
 * 2) Click on ‘Questionnaires’ link.
 * 3) Create ‘New Public review’
 * 4) Click on ‘Create‘
 * 5) Change the min, max or public values and ‘update’.
 * 6) Click on ‘Add’ after choosing type of question.
 * 7) Type in values for the question.
 * 8) Click ‘Save review questionnaire’
 * 1) Click ‘View/Edit Advice’
 * 2) Edit the advice. (Only criterion and scale types have advice)
 * 3) Click ‘Save and redisplay advice’
 * 4) Click ‘Back to questionnaire’ link

Functional Tests for Questionnaire
The test is to check whether a questionnaire can be created and the functionalities of the function are working. The above code is written in Capybara and it creates a public questionnaire of type review.

There are three text fields and one dropdown box which have to be filled to create the questionnaire. The values are populated using the fill_in function for the text fields and the select function for the dropdown. Finally, the ‘create’ button is clicked. For the test to pass successfully, there has to be a new questionnaire named ‘Review 1’ which exists in the test database. Hence, we use the expect function to check for the presence of the questionnaire. If there is no such questionnaire, then the test has failed and the functionality of the function has not been implemented correctly.

Functional Tests for Question
There are ten types of questions in Expertiza - Criterion, Scale, Dropdown, Checkbox, TextArea, TextField, UploadFile, SectionHeader, TableHeader and ColumnHeader. The question type can be chosen while creating the question from a dropdown menu.

Three different actions can be performed on each question - create, edit and delete. The above code snippet shows a creation workflow for the criterion type question. Once the add button is clicked, a new question is created and the link to remove the question appears along with it. Using this we can test whether, a new question has been created. Also, once the questionnaire is saved, a message appears on the Expertiza system confirming that the questions have been saved. By checking whether the message appears or not we can test whether the functionality has been implemented properly. The above code snippet tests whether the question has been edited successfully or not. When a question has been edited with some content, the same content remains in the text field for the question. This can be used to test the successful editing of the question. The created question can be deleted by using the link ‘Remove’ which has been specified along with it. Also, after successful deletion a message appears implying that the question can be deleted. Thus the presence or absence of this message can be used to test for the delete functionality.

Functional Tests for Advice
Only two types of questions in Expertiza have an advice associated with them - the Scale and Criterion type questions. The number of text areas in the advice page depend upon the number of Scale and Criterion type questions and each question has a number of advice text areas, one for each possible score which can be assigned for a particular question. This is obtained by using the ‘minimum’ and ‘maximum’ possible scores provided while creating the questionnaire.

Two types of actions are possible for the advice - create and edit. The above code snippet shows the way in which the advice is created. The button ‘Edit/View Advice’ is present for each questionnaire and the resulting page has all the text areas for the scale and criterion type questions in the questionnaire. There is also a heading which provides directions to the user that the questionnaire can be edited. This message can be used to test for the button’s functionality. Once the advice is created with some content, the presence of a message implying that the advice is saved and the presence of the saved content can test for the create functionality. The workflow for the edit functionality is similar to that of the create advice functionality.

Running the tests
The tests can be run on the terminal using the command: rspec specfile.rb A seed value is used to randomize the order in which the tests are run. This is because all the tests are independent and so every test must be able to run at any time so that all the functionalities can be tested successfully.

All the tests are run and depending on whether a test passes or fails, we can find out which of the functionalities are successfully implemented in the system.