CSC/ECE 517 Fall 2016/E1701. Accelerate RSpec testing

From Expertiza_Wiki
Revision as of 22:11, 8 November 2016 by Zli36 (talk | contribs)
Jump to navigation Jump to search

Eexpertiza

Rspec

Problem Statement

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.Unfortunately, Expertiza tests are really slow. If you check the TravisCI, it needs more than 9 min to run all tests.

One reason is that we use fixture to create records in test DB each time running tests.
For example, the codes in quiz_spec.rb contain too much create so that prolong testing time.
   # Create an assignment due date
    create(:deadline_type, name: "submission")
    create(:deadline_type, name: "review")
    create(:deadline_type, name: "metareview")
    create(:deadline_type, name: "drop_topic")
    create(:deadline_type, name: "signup")
    create(:deadline_type, name: "team_formation")
    create(:deadline_right)
    create(:deadline_right, name: 'Late')
    create(:deadline_right, name: 'OK')
    create :assignment_due_date, due_at: (DateTime.now + 1)

One solution is building an complete database to one time to support all RSpec test without create new records.

Related Work

  • Classes involved: All RSpec test files in Expertiza.
  • Database involved: Expertiza_test

Task

Formally, you need to:

  • Create the records in test DB according to the content in fixtures.
  • Check each test file and delete certain DB records creation code that insert default records (eg. create(:deadline_type)).
  • And keep all the test cases passing when using test DB and make sure the time running test cases is shorter than before.
  • You should submit the sql file of test DB to Expertiza.

Design

Database design

We design a expertiza_test database to save the test date used for Rspec. The test database owns the same structure as the real expertiza database, including the relations between tables and some restriction of attribute like it cannot be null or some other requirements for different attributes. Besides, the data in test database is the same as the data in factories part in spec, which includes FeedbackResponseMap.rb, Respone.rb, factories.rb, quiz_factory.rb. In this situation we do not need to create some data before testing, and we can use the data in test DB directly. Because of it, the overhead of testing cases will experience obvious decreasing.

feature test design

To accelerate the feature test, we have to eliminate pseudo data creation. Now all the feature tests have to create their own data before each test. After building a test database, all the pseudo data creation statement can be removed from the test files. Instead, the tests reference data stored in the test database.