CSC/ECE 517 Fall 2018- Project E1848: Writing unit tests for assignment team.rb: Difference between revisions
Line 17: | Line 17: | ||
This function in AssignmentTeam.rb checks if the '''participant''' passed as argument is a member of the team or not. | This function in AssignmentTeam.rb checks if the '''participant''' passed as argument is a member of the team or not. | ||
Test cases checked for are-: | Test cases checked for are-: <br> | ||
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. | 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. | ||
Line 26: | Line 26: | ||
allow(AssignmentParticipant).to receive(:find_by).with(user_id: user1.id, parent_id: team.parent_id).and_return(participant1) | 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 | expect(team.includes?(participant1)).to eq true | ||
end | |||
end | |||
</pre> | |||
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. | |||
<pre> | |||
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 | ||
end | end |
Revision as of 03:13, 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.
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