CSC/ECE 517 Fall 2019 - E1955.Write unit tests for student task.rb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 92: Line 92:
   )
   )
end
end
</pre
</pre>
=== Team ===
=== Team ===



Revision as of 21:14, 6 November 2019

This page provides a description of the Expertiza based OSS project.


About Expertiza

Expertiza is an open source project based on Ruby on Rails framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.

This project in particular intends that the students collaborate with each other and work on making enhancements to the code base by applying the concepts of Rails,RSpec, DRY code,Test driven development etc. This provides an opportunity for students to contribute to an open source project and learn further about software deployment etc.


About RSpec

RSpec is a unit test framework for the Ruby programming language. RSpec is different than traditional xUnit frameworks like JUnit because RSpec is a Behavior driven development tool. What this means is that, tests written in RSpec focus on the "behavior" of an application being tested. RSpec does not put emphasis on, how the application works but instead on how it behaves, in other words, what the application actually does.Each RSpec file contains one or more tests. Each test ensures if a particular feature of our website is working properly.The output of an RSpec run will tell you exactly what features aren't working. The benefit is that tested code is unlikely to break unnoticed.The tests are run every time someone makes, or updates, a Pull Request.

Description of the current project

The following is an Expertiza based OSS project which deals primarily with the student_task.rb and student_task_spec.rb. It focuses on writing RSpec unit tests for the code affected or added. The goal of this project is to attempt to add sufficient unit tests to this part of the application and increase its path coverage to above 90 percent.

There are few tests for student_task.rb. We had to test the following functions:

  • complete?

This function returns true if the participant stage deadline is "complete" or else return false.

  • content_submitted_in_current_stage?

This function returns true if the participant has submitted hyperlinks in the current stage and the stage is in "submission"

  • hyperlinks

This function returns all the hyperlinks submitted by the participant team

  • in_work_stage?

A assignment is said to be in work stage if its stage is any of "submission", "review" or "metareview"

  • incomplete?

This function returns true if the participant stage deadline is not "complete" or else return false.

  • metareviews_given? * reviews_given?

A participant can review other people's work and add comments. Also a user can review a review, called "metareview" that is given to him. A review comment is mapped to assignments or other reviews by the table response_tags via the reviewed_object_id. This method checks if the participant has given any metareview and return true otherwise.

  • metareviews_given_in_current_stage?

This function checks if the assignment is in "metareview" stage and metareviews.

  • not_started?

This function checks if the assignment is in any of "submission", "review" or "metareview" stage

  • relative_deadline
  • reviews_given_in_current_stage?
  • revision?
  • from_participant(participant)
  • from_participant_id(id)
  • from_user(user)
  • get_author_feedback_data(participant_id, timeline_list)
  • get_due_date_data(assignment, timeline_list)
  • get_peer_review_data(participant_id, timeline_list)
  • get_submission_data(assignment_id, team_id, timeline_list)
  • get_timeline_data(assignment, participant, team)
  • teamed_students(user, ip_address = nil)
  • started?
  • topic_name

Test Plan

  • Mock Objects
let(:participant) { build(:participant, id: 1, user_id: user.id, parent_id: assignment.id) }
let(:participant2) { build(:participant, id: 2, user_id: user2.id, parent_id: assignment.id) }
let(:participant3) { build(:participant, id: 3, user_id: user3.id, parent_id: assignment2.id) }
let(:user) { create(:student) }
let(:user2) { create(:student, name: "qwertyui", id: 5) }
let(:user3) { create(:student, name: "qwertyui1234", id: 6) }
let(:course) { build(:course) }
let(:assignment) { build(:assignment, name: 'assignment 1') }
let(:assignment2) { create(:assignment, name: 'assignment 2', is_calibrated: true) }
let(:team) { create(:assignment_team, id: 1, name: 'team 1', parent_id: assignment.id, users: [user, user2]) }
let(:team2) { create(:assignment_team, id: 2, name: 'team 2', parent_id: assignment2.id, users: [user3]) }
let(:team_user) { create(:team_user, id: 3, team_id: team.id, user_id: user.id) }
let(:team_user2) { create(:team_user, id: 4, team_id: team.id, user_id: user2.id) }
let(:team2_user3) { create(:team_user, id: 5, team_id: team2.id, user_id: user3.id) }
let(:course_team) { create(:course_team, id: 3, name: 'course team 1', parent_id: course.id) }
let(:cource_team_user) { create(:team_user, id: 6, team_id: course_team.id, user_id: user.id) }
let(:cource_team_user2) { create(:team_user, id: 7, team_id: course_team.id, user_id: user2.id) }
let(:topic) { build(:topic) }
let(:topic2) { create(:topic, topic_name: "TestReview") }
let(:due_date) { build(:assignment_due_date, deadline_type_id: 1) }
let(:deadline_type) { build(:deadline_type, id: 1) }
let(:review_response_map) { build(:review_response_map, assignment: assignment, reviewer: participant, reviewee: team2) }
let(:metareview_response_map) { build(:meta_review_response_map, reviewed_object_id: 1) }
let(:response) { build(:response, id: 1, map_id: 1, response_map: review_response_map) }
let(:response2) { build(:response, id: 2, map_id: 1, response_map: review_response_map) }
let(:submission_record) {build(:submission_record, id:1, team_id: 1, assignment_id: 1) }    #added for submission_record method call test.
let(:student_task) do
  StudentTask.new(
    participant: participant,
    assignment: participant.assignment,
    topic: participant.topic,
    current_stage: participant.current_stage,
    stage_deadline: (Time.parse(participant.stage_deadline) rescue Time.now + 1.year)
  )
end

Team

Carmen Bentley,Mentor

  • Tushar Kundra,tkundra
  • Ram Chavali,ramlohith
  • Ayushi Rungta,Rungta1001

Running Tests

What we need to do is to set up the environment and complete the 'student_task.rb' and 'student_task_spec.rb' to increase the path coverage from only 43.0% with 43 lines covered and 57 lines missed to above 90%.

You can run RSpec tests by executing the command:


rspec spec/models/student_task_spec.rb

After that, you can see the detailed coverage information by opening this file in your Expertiza folder.


coverage/index.html

Our work

The code we created can be found below. We have also linked the video of our tests running with coverage to showcase the work we have done.

Test Coverage: Initial Final

Problem Statement

The following tasks were accomplished in this project:

  • Complete the insufficient unit tests for student_task.rb.
  • Increase path coverage from only 31.91% with 30 lines covered to above 92.55% with 87 lines covered.
  • Cover edge cases.
  • High branch coverage to be achieved.

There are different tasks that a student can perform.

  • He can see all the assignments that he has been assigned to.
  • He can see details of each assignment like marks, his team, send invitation to student to join a team
  • Review other students' work

Student Task Home Page Assignment Submission Tasks

Running the Project Locally

The project could be run locally by cloning the Github repository Expertiza and then running the following commands sequentially.


bundle install
rake db:create:all
rake db:migrate
rails s


Issues/Erros During Testing

  • While creating the test for "reviews_given?", given below, it seems the function is returning string value instead of boolean value as "j.class.to_s[/Review/]" gives a string when the class of "j" starts with "Review"
  def reviews_given?
    response_maps.inject(nil) {|i, j| i || (j.response && j.class.to_s[/Review/]) }
  end