CSC/ECE 517 Fall 2018- Project E1848: Writing unit tests for assignment team.rb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 76: Line 76:
         expect(team.fullname).to eq "abcd"
         expect(team.fullname).to eq "abcd"
       end
       end
    end
</pre>
==== Function name: review_map_type ====
This function in AssignmentTeam.rb always provides the name of the review map type which is '''ReviewResponseMap'''.
Hence, the unit test also always checks if the response of this method is the string '''"ReviewResponseMap"''' or not.
<pre>
    it "provides the review map type" do
      expect(team.review_map_type).to eq "ReviewResponseMap"
     end
     end
</pre>
</pre>

Revision as of 03:32, 2 November 2018

The purpose of this project is to improve the coverage and quality of the unit tests for the assignment team model in Expertiza. This project comprised the program 3 assignment of CSC/ECE 517 in fall 2018 and is entitled "Project E1848: Writing unit tests for assignment_team.rb." The source code for this project is in pull request #1228 of the Expertiza project on GitHub.

Key Contributions

Out of the 30 methods defined for the model AssignmentTeam.rb, test case was written for only one. Our contribution was to successfully add test cases for all remaining 29 methods.

Hence, increasing the coverage from 5% to 100%.

The Class under Test

AssignmentTeam

Test Plan

Test Design

Test Structure

Listed below are the functionalities and the Rspec unit tests corresponding to the function names along with a list of scenarios tested.

Function name: includes?(participant)

This function in AssignmentTeam.rb checks if the participant passed as argument is a member of the team or not. For this, we utilize factorybot to build a user and a participant1 as follows-:

  let(:user1) { build(:student, id: 2) }
  let(:participant1) { build(:participant, id: 1) }

Test cases checked for are-:
1) when the team receives a user, that user is allowed to become a team participant. The method returns True for the given participant passed as argument.

    context "when an assignment team has one participant" do
      it "includes one participant" do
        allow(team).to receive(:users).with(no_args).and_return([user1])
        allow(AssignmentParticipant).to receive(:find_by).with(user_id: user1.id, parent_id: team.parent_id).and_return(participant1)
        expect(team.includes?(participant1)).to eq true
      end
    end

2) when the team receives a user with no arguments, that user is not allowed to become a team participant. The method returns False for the given participant passed as argument.

    context "when an assignment team has no users" do
      it "includes no participants" do
        allow(team).to receive(:users).with(no_args).and_return([])
        expect(team.includes?(participant1)).to eq false
      end
    end

Function name: parent_model

This function in AssignmentTeam.rb always provides the name of the parent model which is Assignment.

Hence, the unit test also always checks if the response of this method is the string "Assignment" or not.

    it "provides the name of the parent model" do
      expect(team.parent_model).to eq "Assignment"
    end

Function name: self.parent_model(id)

This function in AssignmentTeam.rb takes in as argument id of the current Assignment for the team and returns an instance of the parent model.

Hence the unit test checks if the instance returned by this method for a given assignment id, matches the assignment or not.

    it "provides the instance of the parent model" do
      allow(Assignment).to receive(:find).with(1).and_return(assignment)
      expect(AssignmentTeam.parent_model(1)).to eq assignment
    end

Function name: fullname

This function in AssignmentTeam.rb print out the name for the current class instance. for this we first build an assignment team instance and assign it the name "abcd".

Hence the unit test checks if the assignment team has a name, and returns that same name.

    context "when the team has a name" do
      it "provides the name of the class" do
        team = build(:assignment_team, id: 1, name: "abcd")
        expect(team.fullname).to eq "abcd"
      end
    end

Function name: review_map_type

This function in AssignmentTeam.rb always provides the name of the review map type which is ReviewResponseMap.

Hence, the unit test also always checks if the response of this method is the string "ReviewResponseMap" or not.

    it "provides the review map type" do
      expect(team.review_map_type).to eq "ReviewResponseMap"
    end

Test Coverage

Stubs for Isolating the UUT

DRY Testing Practices

Factories and the let RSPEC Helper Method

Contexts

Testing Framework

RSPEC

Bugs Detected

Results

Future Work

References