CSC/ECE 517 Spring 2019 - E1922. Write tests for assessment360 controller.rb

From Expertiza_Wiki
Jump to navigation Jump to search

Introduction

Background

Expertiza

Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. (https://github.com/expertiza/expertiza)

RSpec

RSpec is a 'Domain Specific Language' (DSL) testing tool written in Ruby to test Ruby code. It is a behavior-driven development (BDD) framework which is extensively used in the production applications. The basic idea behind this concept is that of Test Driven Development (TDD) where the tests are written first and the development is based on writing just enough code that will fulfill those tests followed by refactoring. It contains its own mocking framework that is fully integrated into the framework based upon JMock. The simplicity in the RSpec syntax makes it one of the popular testing tools for Ruby applications. The RSpec tool can be used by installing the rspec gem which consists of 3 other gems namely rspec-core, rspec-expectation and rspec-mock. (https://en.wikipedia.org/wiki/RSpec)

Team

Zhewei Hu (zhu6) (mentor)

  • Jasmine Wang (jfwang2)
  • Louis Le (lle3)

Project

Task

Problem statement

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

  • action_allowed
  • all_students_all_reviews
  • course_student_grade_summary
  • populate_hash_for_all_students_all_reviews(assignment,course_participant,reviews,hash_per_stu,overall_review_grade_hash,overall_review_count_hash, review_info_per_stu)
  • find_peer_review_score(user_id, assignment_id)
  • format_topic(topic)
  • format_score(score)

Overall tasks

  • Write RSpec integration tests to make the statement coverage above 90%.
  • Cover as many edge cases as you can.
  • Achieve as high branch coverage as you can.

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.

With the goal of getting at least 90% coverage, our tests got about 97.94%. The way we split up the work by having Jasmine take care of the function: all_students_all reviews while Louis took care of course_student_grade_summary. This helped with potential merge conflicts since both these functions are the biggest of the file and working on them would allow both to make progress at the same time.

Files

The following files were the ones either edited or used as aid.

   * File being tested. (Goal is at least 90%)
   * Test file using RSpec.
   * Super useful file that aided in mocking variable

Running Tests

In order to run the integration test, run the following command via terminal:

  rspec ./spec/controller/assessment360_controller.rb

Test Outline/Plan

Below shows the outline of what our test look like:

assessment360controller

   #all_students_all_reviews
       when it redirects to back and flashes error as there are no participants
       when it has participants, next assignment participants does not exist and avoid divide by zero
       when it has participants, next assignment participant exists, but there are reviews
   #course_student_grade_summary
       when course does not have participants
       when method is called
       when it redirects back and flashes error as there are no participants
       when it has participants, next assignment participant does not exist
       when it has participants, next assignment participant exist, but no team id exists