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

From Expertiza_Wiki
Jump to navigation Jump to search
Line 66: Line 66:
== Testing Implementation ==
== Testing Implementation ==


*''initialize'' : This tests that the VmQuestionResponse is initialized with the appropriate round number.
<pre>
</pre>


    it 'adds reviews' do
      allow(ReviewResponseMap).to receive_messages(:get_assessments_for => [review], :find => mapping)
      allow(Participant).to receive_messages(:find => ppnt1)
      vm_rsp.add_reviews(ppnt0, team, false)
      expect(vm_rsp.list_of_reviews.size).to eq 1
      expect(vm_rsp.list_of_reviewers.size).to eq 1
      expect(vm_rsp.list_of_reviews).to eq [review]
    end


This code tests that the add_reviews method works when VMQuestionResponse has been initialized with @questionnaire_type = "ReviewQuestionnaire"
*''add_reviews'' : This tests that the add_review adds reviews and reviewers to the VmQuestionResponse from a given review
:- stub simulates the
<pre>
</pre>




    context 'when given a team' do
*''display_team_members'' : This tests that the VmQuestionResponse can print out the appropriate team member names.
<pre>
      it 'displays the members of the team' do
</pre>
        team = double('team')
        ppnt2 = double('ppnt2')
        allow(ppnt2).to receive_messages :fullname => 'R'
        team_member_names = [ppnt0, ppnt1, ppnt2]
        allow(team).to receive_messages(:participants => team_member_names)
        out = 'Team members:'
        vm_rsp.add_team_members(team)
        team.participants.each do |participant|
          out = out + " (" + participant.fullname + ") "
        end
        expect(vm_rsp.display_team_members).to eq out
      end
    end


This code tests that when VMQuestionResponse is initialized with a team the team members can be displayed


*''add_answers'' : This tests that the VmQuestionResponse adds all of the review scores from its reviews to VmQuestionResponseCells
in VmQuestionResponseRows.
<pre>
</pre>


    context 'when given a list of valid questions' do
      let(:qs) { qs = Array.new(1) { question2 } }
      it 'can calculate the max score for the questionnaire' do
        vm_rsp.add_questions qs
        expect(vm_rsp.max_score).to eq 5
        expect(vm_rsp.list_of_rows.size).to eq 1
        expect(vm_rsp.max_score_for_questionnaire()).to eq qs.size * rq.max_question_score
      end
    end


This code tests VMQuestionResponse knows the max score for the questionnaire.


 
*''get_number_of_comments_greater_than_10_words'' : This tests that VmQuestionResponse only finds comments that have at least 10 words.
    it 'has the round value of the given questionnaire' do
<pre>
</pre>
      expect(vm_rsp.round).to eq 1
    end
 
This code checks that VMQuestionResponse knows the value of @round for the given questionnaire.
 
 
  context 'is initialized with an AuthorFeedbackQuestionnaire' do
    [mock setup omitted for brevity]
    it 'adds reviews' do
      # review = double('review1')
      # review.stub(:map_id => 1, :response_id => 1)
      # allow(review).to receive_messages(:map_id => 1)
      # ppnt0 = double('ppnt0')
      # allow(ppnt0).to receive_messages(:feedback => [review])
      # ppnt1 = double('ppnt1')
      # allow(ppnt1).to receive_messages(:fullname => 'Python')
      # mapping = double
      # allow(mapping).to receive_messages(:first => mapping, :reviewer_id => 2)
      # allow(FeedbackResponseMap).to receive_messages(:where => mapping)
      # allow(Participant).to receive_messages(:find => ppnt1)
      # vm_rsp.add_questions qs
      # vm_rsp.add_reviews(ppnt0, '', false)
      # expect(vm_rsp.list_of_reviews.size).to eq 1
      # expect(vm_rsp.list_of_reviewers.size).to eq 1
      # expect(vm_rsp.list_of_reviews).to eq [ppnt1]
    end
    it 'adds answers' do
      allow(FeedbackResponseMap).to receive_messages(:where => mapping)
      allow(Participant).to receive_messages(:find => ppnt1)
      allow(Answer).to receive_messages(:where => [ans])
      allow(TagPromptDeployment).to receive_messages(:where => [tag_dep])
      allow(Question).to receive_messages(:find => question2)
      allow(TagPrompt).to receive_messages(:find => true)
      allow(VmTagPromptAnswer).to receive_messages(:new => '')
      allow(VmQuestionResponseScoreCell).to receive_messages(:new => '')
      vm_rsp.add_questions qs
      vm_rsp.add_reviews(ppnt0, '', false)
    end
    it 'gets the number of comments greater than 10 words' do
      allow(FeedbackResponseMap).to receive_messages(:where => mapping)
      allow(Participant).to receive_messages(:find => ppnt1)
      allow(Answer).to receive_messages(:where => [ans])
      allow(TagPromptDeployment).to receive_messages(:where => [tag_dep])
      allow(Question).to receive_messages(:find => question2)
      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)
      vm_rsp.add_questions qs
      vm_rsp.add_reviews(ppnt0, '', false)
      expect(vm_rsp.list_of_rows.size).to eq 1
      vm_rsp.get_number_of_comments_greater_than_10_words
      expect(vm_rsp.list_of_rows[0].countofcomments).to eq 7
    end
  end
 
The above tests cover the scenario in which VMQuestionResponse is initialized with @questionnaire_type = "AuthorFeedbackQuestionnaire". We check that VMQuestionResponse can add revews, add answers, and retrieve the number of comments greater than 10 words in length. Here the test for add_reviews is commented out because it is still being developed.
 
 
  context 'is initialized with an TeammateReviewQuestionnaire' do
    let(:tmrq) { create(:questionnaire, name: "TeammateReviewQuestionnaire",
                        type: 'TeammateReviewQuestionnaire') }
    let(:vm_rsp) { VmQuestionResponse.new( tmrq, assignment, 1 ) }
    let(:question2) { create(:question, questionnaire: tmrq, weight: 2, id: 2, type: 'good') }
    let(:qs) { qs = Array.new(1) { question2 } }
    it 'adds reviews' do
      allow(TeammateReviewResponseMap).to receive_messages(:where => mapping)
      allow(Participant).to receive_messages(:find => ppnt1)
      vm_rsp.add_questions qs
      vm_rsp.add_reviews(ppnt0, '', false)
      expect(vm_rsp.list_of_reviews.size).to eq 1
      expect(vm_rsp.list_of_reviewers.size).to eq 1
      expect(vm_rsp.list_of_reviews).to eq [review]
    end
  end
 
This code checks that we can add reviews when VMQuestionResponse is initialized with @questionnaire_type = "TeammateReviewQuestionnaire".
 
 
  context 'is initialized with an MetareviewQuestionnaire' do
    let(:mrq) { create(:questionnaire, name: "MetareviewQuestionnaire", type: 'MetareviewQuestionnaire') }
    let(:question2) { create(:question, questionnaire: mrq, weight: 2, id: 2, type: 'good') }
    let(:qs) { qs = Array.new(1) { question2 } }
    let(:vm_rsp) { VmQuestionResponse.new( mrq, assignment, 1 ) }
    it 'adds reviews' do
      allow(MetareviewResponseMap).to receive_messages(:where => mapping)
      allow(Participant).to receive_messages(:find => ppnt1)
      vm_rsp.add_questions qs
      vm_rsp.add_reviews(ppnt0, '', false)
      expect(vm_rsp.list_of_reviews.size).to eq 1
      expect(vm_rsp.list_of_reviewers.size).to eq 1
      expect(vm_rsp.list_of_reviews).to eq [review]
    end
  end
 
This code checks that we can add reviews when VMQuestionResponse is initialized with @questionnaire_type = "MetaReviewQuestionnaire".


== Results ==
== Results ==

Revision as of 04:37, 10 November 2018

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.


  • add_reviews : This tests that the add_review adds reviews and reviewers to the VmQuestionResponse from a given review
- stub simulates the


  • display_team_members : This tests that the VmQuestionResponse can print out the appropriate team member names.


  • add_answers : This tests that the VmQuestionResponse adds all of the review scores from its reviews to VmQuestionResponseCells

in VmQuestionResponseRows.



  • get_number_of_comments_greater_than_10_words : This tests that VmQuestionResponse only finds comments that have at least 10 words.

Results

We have now attained 91% coverage.

Links/Resources

spec/models/vm_question_response_spec.rb