CSC/ECE 517 Fall 2016/E1670. Unit tests for answers.rb
E1670 . Unit tests for answers.rb
This wiki page is for the description of changes made under E1670 OSS assignment for Fall 2016, CSC/ECE 517.
Background
Expertiza is an Open Source web application developed on Ruby On Rails platform. It is a platform which allows students to take assignments posted by the course instructors. Expertiza allows students to select assignment topics, form teams and submit their work. It also allows them to review other students' submissions and improve their work based on this feedback.
Project Description
In Expertiza, each questionnaire contains many questions, those question may have different types (e.g. checkbox, criterion, etc). When a user fills in a rubric, the responses for each question will become an answer record. The responses of rubrics are stored in answers table in DB. The answer.rb is the model for the answers table in DB. Answer.rb model does not have any test cases and the aim of the project is to write fast, effective and flexible unit test cases that offer maximum code coverage.
Functions in answers.rb
Function Name : Compute_scores
Compute_scores is a function in model answer.rb which gives the average, maximum and minimum scores obtained in a series a responses/assessments. It has two input parameters: List of assessments and questions. The function iterates over each assessment to get the total score of that assessment. If the response or review is invalid, that assessment won’t be considered in the calculation of the score average. After iterating over all assessments, Max score, and Min scores are calculated along with the average score based on the number of valid assessments. Their scores are returned by the function.
Rspec Unit Test : Compute_scores
Following scenarios are tested:
- To return scores as nil if the input list of assessments is nil. This is to make sure no Null Pointer exceptions are thrown by the code
- To return a particular score when a single valid assessment is given as an input.
- To return a particular score when multiple valid assessments are given as an input. This is to test the looping functionality of the method.
- To return a particular score when invalid assessments are given as an input. The validity and total scores are returned by a mock and not by the actual functions. This is to make the test cases less rigid so that failure of dependent functions do not disrupt the functionality of interface level tests.
- To return a particular score when invalid flag is nil. Invalid flag can either be 0,1 or nil. Nil situation is tested to prevent NullPointer Exceptions
- To check if the method get_total_score is called with the right parameters.