CSC/ECE 517 Fall 2018/E1849 Write Unit Tests for vm question response.rb

From Expertiza_Wiki
Jump to navigation Jump to search

Introduction

VMQuestionResponse in Brief

This class acquires reviews from a given questionnaire and assignment, and creates a heat map visualization of the review scores a reviewee received from other people (reviewers) for an assignment.


Objective

There are currently no test cases for vm_question_response.rb. We seek to create unit tests to attain at least 90% coverage by line.

Team

Matt Leader (mfleader@ncsu.edu)

Jonathan Gill (jtgill@ncsu.edu)

Files Involved

app/models/vm_question_response.rb

spec/models/vm_question_response_spec.rb

Testing Plan

Testing Strategy: Unit Test

Testing VMQuestionResponse hinges upon collaboration verification, so that we know VMQuestionResponse is getting the right messages from the right classes, so that it can appropriately create its data structures.

We first went through each method of the VMQuestionResponse class and determined whether the method was a command, or query and whether the method was incoming, outgoing, or sent-to-self. For each method we will write tests for valid and invalid inputs as well as edge cases.

Here is an outline of our implementation strategy:

To describe VMQuestionResponse

1) Test initialize

  • in the context when VMQuestionResponse is initialized with a review questionnaire
  • in the context when VMQuestionResponse is initialized with any other questionnaire type

2) Test add questions

  • in the context when VMQuestionResponse is given a list of questions

3) Test add_reviews

  • in the context when VMQuestionResponse is initialized with a review questionnaire
  • in the context when VMQuestionResponse is initialized with a author feedback questionnaire
  • in the context when VMQuestionResponse is initialized with a teammate review questionnaire
  • in the context when VMQuestionResponse is initialized with a metareview questionnaire

4) Test display_team_members

5) Test add_team_members

6) Test listofteamparticipants

7) Test max_score_for_questionnaire

8) Test add_answer

9) Test get_number_of_comments_greater_than_10_words

Testing Implementation

  • initialize : This tests that the VmQuestionResponse is initialized with the appropriate round number.
 describe '#initialize' do
    context 'when intitialized with a review questionnaire' do
      let(:response) { VmQuestionResponse.new(review_questionnaire, assignment, 1) }
      it 'initializes the instance variables' do
        expect(response.round).to eq 1
        expect(response.questionnaire_type).to eq "ReviewQuestionnaire"
        expect(response.rounds).to eq 2
      end
    end
    context 'when intitialized with any other questionnaire type' do
      let(:response) { VmQuestionResponse.new(metareview_questionnaire, assignment, 1) }
      it 'initializes the instance variables' do
        expect(response.round).to eq 1
        expect(response.questionnaire_type).to eq "MetareviewQuestionnaire"
        expect(response.rounds).to eq 2
      end
    end
  end
  • add_questions: This tests that the VmQuestionResponse adds questions from a given review
  describe '#add_questions' do
    let(:response) { VmQuestionResponse.new(review_questionnaire, assignment, 1) }
    it 'adds questions' do
      response.add_questions questions
      expect(response.max_score).to eq 5
      expect(response.list_of_rows.size).to eq 1
      expect(response.max_score_for_questionnaire()).to eq questions.size * review_questionnaire.max_question_score
    end
  end
  • add_reviews : This tests that the VmQuestionResponse adds reviews and reviewers from a given review
  describe '#add_reviews' do
    context 'when initialized with a review questionnaire' do
      let(:response) { VmQuestionResponse.new(review_questionnaire, assignment, 1) }
      it 'adds reviews' do
        allow(ReviewResponseMap).to receive_messages(:get_assessments_for => [review], :find => mapping)
        allow(Participant).to receive_messages(:find => participant1)
        response.add_reviews(participant0, team, false)
        expect(response.list_of_reviews.size).to eq 1
        expect(response.list_of_reviewers.size).to eq 1
        expect(response.list_of_reviews).to eq [review]
      end
    end
    context 'when initialized with a author feedback questionnaire' do
      let(:response) { VmQuestionResponse.new(author_feedback_questionnaire, assignment, 1) }
      it 'adds reviews' do
        allow(FeedbackResponseMap).to receive_messages(:where => mapping)
        allow(Participant).to receive_messages(:find => participant1)
        response.add_reviews(participant0, team, false)
        expect(response.list_of_reviews.size).to eq 1
        expect(response.list_of_reviewers.size).to eq 1
        expect(response.list_of_reviews).to eq [review]
      end
    end
    context 'when initialized with a teammate review questionnaire' do
      let(:response) { VmQuestionResponse.new(teammate_review_questionnaire, assignment, 1) }
      it 'adds reviews' do
        allow(TeammateReviewResponseMap).to receive_messages(:where => mapping)
        allow(Participant).to receive_messages(:find => participant1)
        response.add_reviews(participant0, team, false)
        expect(response.list_of_reviews.size).to eq 1
        expect(response.list_of_reviewers.size).to eq 1
        expect(response.list_of_reviews).to eq [review]
      end
    end
    context 'when initialized with a meta review type' do
      let(:response) { VmQuestionResponse.new(metareview_questionnaire, assignment, 1) }
      it 'adds reviews' do
        allow(MetareviewResponseMap).to receive_messages(:where => mapping)
        allow(Participant).to receive_messages(:find => participant1)
        response.add_reviews(participant0, team, false)
        expect(response.list_of_reviews.size).to eq 1
        expect(response.list_of_reviewers.size).to eq 1
        expect(response.list_of_reviews).to eq [review]
      end
    end
  end


  • display_team_members : This tests that the VmQuestionResponse can print out the appropriate team member names.
  describe '#display_team_members' do
    let(:response) { VmQuestionResponse.new(review_questionnaire, assignment, 1) }
    it 'displays the members of the team' do
      team = double('team')
      participant2 = double('participant2')
      allow(participant2).to receive_messages :fullname => 'R'
      team_member_names = [participant0, participant1, participant2]
      allow(team).to receive_messages(:participants => team_member_names)
      out = 'Team members:'
      response.add_team_members(team)
      team.participants.each do |participant|
        out = out + " (" + participant.fullname + ") "
      end
      expect(response.display_team_members).to eq out
    end
  end


  • add_answer : This tests that the VmQuestionResponse adds all of the review scores from its reviews to VmQuestionResponseCells in VmQuestionResponseRows.
  describe '#add_answer' do
    let(:response) { VmQuestionResponse.new(author_feedback_questionnaire, assignment, 1 ) }
    let(:tag_dep) do
      tag_dep = double('tag_dep')
      allow(tag_dep).to receive_messages(:question_type => question.type,
                                         :answer_length_threshold => 4,
                                         :tag_prompt_id => 1)
      tag_dep
    end
    it 'adds an answer' do
      allow(FeedbackResponseMap).to receive_messages(:where => mapping)
      allow(Participant).to receive_messages(:find => participant1)
      allow(Answer).to receive_messages(:where => [answer])
      allow(TagPromptDeployment).to receive_messages(:where => [tag_dep])
      allow(Question).to receive_messages(:find => question)
      allow(TagPrompt).to receive_messages(:find => true)
      allow(VmTagPromptAnswer).to receive_messages(:new => '')
      allow(VmQuestionResponseScoreCell).to receive_messages(:new => '')

      response.add_questions questions
      response.add_reviews(participant0, '', false)
    end
  end


  • get_number_of_comments_greater_than_10_words : This tests that VmQuestionResponse only finds comments that have at least 10 words.
  describe '#get_number_of_comments_greater_than_10_words' do
    let(:response) { VmQuestionResponse.new(author_feedback_questionnaire, assignment, 1 ) }
    let(:tag_dep) do
      tag_dep = double('tag_dep')
      allow(tag_dep).to receive_messages(:question_type => question.type,
                                         :answer_length_threshold => 4,
                                         :tag_prompt_id => 1)
      tag_dep
    end
    it 'returns number of comments greater than 10 words' do
      allow(FeedbackResponseMap).to receive_messages(:where => mapping)
      allow(Participant).to receive_messages(:find => participant1)
      allow(Answer).to receive_messages(:where => [answer])
      allow(TagPromptDeployment).to receive_messages(:where => [tag_dep])
      allow(Question).to receive_messages(:find => question)
      allow(TagPrompt).to receive_messages(:find => true)
      allow(VmTagPromptAnswer).to receive_messages(:new => '')
      allow(VmQuestionResponseScoreCell).to receive_messages(:new => '')
      
      row = double('row')
      allow(row).to receive_messages(:countofcomments => 7, :question_id => 2,
        :question_max_score => 5, :score_row => [3])
      allow(VmQuestionResponseRow).to receive_messages(:new => row)

      response.add_questions questions
      response.add_reviews(participant0, '', false)
      expect(response.list_of_rows.size).to eq 1
      response.get_number_of_comments_greater_than_10_words
      expect(response.list_of_rows[0].countofcomments).to eq 7
    end
end

Results

We have now attained 97.25% coverage.

Links/Resources

spec/models/vm_question_response_spec.rb

Testing Video(YouTube)