CSC/ECE 517 Fall 2017/E1762 Test various kinds of response-map hierarchies

From Expertiza_Wiki
Revision as of 03:53, 28 October 2017 by Adupadhy (talk | contribs)
Jump to navigation Jump to search

Expertiza Background

Expertiza is a web application where students can submit and peer-review learning objects (articles, codes, websites, etc). Instructors add and edit assignments to Expertiza. Students can be assigned in teams based on their selection of the topics. The Expertiza project is supported by the National Science Foundation. The Expertiza project is software to create reusable learning objects through peer review. It also supports team projects, and the submission of almost any document type, including URLs and wiki pages.

Introduction

Problem Statement

In Expertiza, there are several types of response maps (model files in app/models). They basically map responses, the one who submitted the response and the one to whom it is directed to. The parent class is ResponseMap, and the subclasses are (from most used to least used) ReviewResponseMap, TeammateReviewResponseMap, FeedbackResponseMap, QuizResponseMap, AssignmentSurveyResponseMap, BookmarkRatingResponseMap, MetareviewResponseMap, SelfReviewResponseMap, CourseSurveyResponseMap, GlobalSurveyResponseMap. You can find the database structure for these response maps here. For each response map record, there is one reviewer_id and reviewee_id. However, you need to check the code to learn what are recorded as reviewer/reviewee ids (see the foreign key constraints at the beginning of each model, they could be participant_id, team_id, etc. as per that model). These models do not have any unit tests.


Work to be done

• Create a factory for each response map models in factories.rb file (review_response_map factory has already existed).

• Then create test files in spec/models (you can refer to answer_spec.rb, due_date_spec.rb for how to write specs); write model specs for methods (if you find any method has no caller, remove the method instead of write tests for it). Good tests means their coverage is maximum, so try to cover as much methods and conditions as possible. ---

Files to be used or created

To write the unit tests for the models, we need to define the spec files for the models. But before that, we need to understand the working of the methods. For this we use the following files (in app\models) –


• Response_map.rb

• Review_response_map.rb

• Teammate_review_response_map.rb

• Feedback_response_map.rb

• Quiz_response_map.rb

• Assignment_survey_response_map.rb

• Bookmark_rating_response_map.rb

• Metareview_response_map.rb

• Self_review_response_map.rb

• Course_survey_response_map.rb

• Global_survey_response_map.rb


While writing our tests we will need a way to set up database records in a way to test against them in different scenarios. This is done by creating factories for each response map model in the spec/factories/factories.rb file.


Now, we use RSpec to create the test cases for these models. These files are added in the spec/models/ folder. The convention of naming the files is MODELNAME_spec.rb, hence we get following files.


• Response_map_spec.rb

• Review_response_map_spec.rb

• Teammate_review_response_map_spec.rb

• Feedback_response_map_spec.rb

• Quiz_response_map_spec.rb

• Assignment_survey_response_map_spec.rb

• Bookmark_rating_response_map_spec.rb

• Metareview_response_map_spec.rb

• Self_review_response_map_spec.rb

• Course_survey_response_map_spec.rb

• Global_survey_response_map_spec.rb


Creating Factories

Each response map model needs its own factory for testing to create relevant mock objects to test the specs written. Hence here is a sample of a factory we created for the response_map.rb model.

   factory :response_map, class: ResponseMap do
       reviewed_object_id 1
       reviewer_id 1
       reviewee_id 1
       type 'ResponseMap'
       calibrate_to 0
    end

Writing Tests

The test cases implemented in the project can be observed in the respective spec files of the models. A sample test written for the some methods of response_map.rb is stated here for reference.

   describe '.get_reviewer_assessments_for' do
       let(:team) { Team.create name: 'team',id: 2, parent_id: 1, type: "AssignmentTeam" }
       it 'should return the responses given to the team by the reviewer' do
         @reviewer = create(:student,id: 5)
         @response_map1 = create(:response_map, id: 1, reviewer_id: 5, reviewed_object_id: 1, reviewee_id: 2, type: "ReviewResponseMap")
         @response1 = create(:response, id: 1, map_id: 1, is_submitted: true)
         expect(ResponseMap.get_reviewer_assessments_for(team,@reviewer)).to eql @response1
       end
     end
   describe '#map_id' do
       it 'should return the id' do
         expect(@response_map.map_id).to be == 1
       end
     end

Testing the RSpec files

To check the test cases of a particular model, run the given command in terminal:

   rspec spec/models/<name of model_spec file>