CSC/ECE 517 Spring 2013/OSS E605B: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 4: Line 4:


The majority of the tests implemented in this project are functional tests of the questionnaire controller. The test cases were written using the [http://api.rubyonrails.org/classes/ActionController/TestCase.html ActionController::TestCase] framework provided by Rails.  
The majority of the tests implemented in this project are functional tests of the questionnaire controller. The test cases were written using the [http://api.rubyonrails.org/classes/ActionController/TestCase.html ActionController::TestCase] framework provided by Rails.  


=== Modifications to Existing QuestionnaireController Test ===
=== Modifications to Existing QuestionnaireController Test ===
Line 10: Line 9:
There were a few tests already written for the Questionnaire controller, but they were not passing initially. We had to modify several things in the test and questionnaire fixture in order to get things up and running. The setup method contained login code that was outdated, and thus each test would result in a redirect due to the invalid login credential. So we looked through other more up to date functional test files and found the correct way to login as a particular user. We also put this code in a helper method so we can call it more easily in different tests if we so choose (more on this in the "Helper Methods" section).
There were a few tests already written for the Questionnaire controller, but they were not passing initially. We had to modify several things in the test and questionnaire fixture in order to get things up and running. The setup method contained login code that was outdated, and thus each test would result in a redirect due to the invalid login credential. So we looked through other more up to date functional test files and found the correct way to login as a particular user. We also put this code in a helper method so we can call it more easily in different tests if we so choose (more on this in the "Helper Methods" section).


=== Modifications to Existing Questionnaire Subclass Tests ===
In addition, we added a new questionnaire fixture (:questionnaire5) to help with our testing. Through debugging the test error messages, we saw that an additional required column called "section" has been added to the "Questionnaire" model, which was contributing to the failures. We added the additional column accordingly in :questionnaire5.


=== Helper Methods ===
=== Helper Methods ===
Line 49: Line 48:
== Questionnaire Subclass Unit Tests ==
== Questionnaire Subclass Unit Tests ==


=== Modifications to Existing Questionnaire Subclass Tests ===
There was only one test in the exiting unit test for AuthorFeedbackQuestionnaire for testing the get_weighted_score method. Even though the test can be run, we found that it was not making assertions as it should, and therefore chose to rewrote test instead.


=== Test Coverage ===
=== Test Coverage ===

Revision as of 17:13, 20 March 2013

Testing - questionnaire

QuestionnaireController Functional Tests

The majority of the tests implemented in this project are functional tests of the questionnaire controller. The test cases were written using the ActionController::TestCase framework provided by Rails.

Modifications to Existing QuestionnaireController Test

There were a few tests already written for the Questionnaire controller, but they were not passing initially. We had to modify several things in the test and questionnaire fixture in order to get things up and running. The setup method contained login code that was outdated, and thus each test would result in a redirect due to the invalid login credential. So we looked through other more up to date functional test files and found the correct way to login as a particular user. We also put this code in a helper method so we can call it more easily in different tests if we so choose (more on this in the "Helper Methods" section).

In addition, we added a new questionnaire fixture (:questionnaire5) to help with our testing. Through debugging the test error messages, we saw that an additional required column called "section" has been added to the "Questionnaire" model, which was contributing to the failures. We added the additional column accordingly in :questionnaire5.

Helper Methods

There are two methods that assist in setting up and running the tests:

  • The setup method
  • The login_user method

The setup method assigns three special instance variables that are associated with the ActionController::TestCase (@controller, @request, and @response). In addition to setting these, the @Questionnaire variable is assigned to id of the :questionnaire5 fixture. This is the default questionnaire fixture that is used in a lot of the test cases. You will also notice that the fixture :admin is being logged in as the default user. This is done so that you don't have explicitly log into a user account for each test case. The only time you would need to call the method to log in for a particular test case is if you needed to test something specifically in another user type's account (for example a student account as is done in test_create_questionnaire_with_student.

 def setup
   @controller = QuestionnaireController.new
   @request = ActionController::TestRequest.new
   @response = ActionController::TestResponse.new
   @Questionnaire = questionnaires(:questionnaire5).id
   login_user(:admin)
 end

The login_user method was created to "DRY out" the code associated with logging a user in. The method signature is:

  def login_user(userType)

If you pass a symbol of the user type you would like to use for a test, it will log in as that user type for the particular test. The parameter name is userType and assumes that there is a fixture with the name of the user type. There seem to be sufficient fixtures for all of the different user types currently, but additional fixtures may need to be created in the future if new user types are added to the system.

Test Coverage

There are three main types of tests that we created.

  • Happy path tests of the controller's public methods. There is a test for every method. (ex: test_new)
  • Sad path tests that passed invalid parameters. (ex: test_edit_questionnaire_with_lower_max_score_than_min)
  • Sad path tests that tried to do things with insufficient access level. (ex: test_create_questionnaire_with_student)

How to Run Controller Test

All of the QuestionnaireController tests are in the questionnaire_controller_test.rb file and can be run as a standard functional test.

Questionnaire Subclass Unit Tests

Modifications to Existing Questionnaire Subclass Tests

There was only one test in the exiting unit test for AuthorFeedbackQuestionnaire for testing the get_weighted_score method. Even though the test can be run, we found that it was not making assertions as it should, and therefore chose to rewrote test instead.

Test Coverage

How to Run Unit Tests

General Information

Members

  • Jonathan Wills - jrwills2
  • Chun Sing Tsui - ctsui
  • Travis Folsom - twfolsom

Highlights of Project

  • Added unit tests for questionnaire subclasses
  • Added functional tests for questionnaire controller
  • 24 total tests
  • Delete test was failing due to a potential bug in the questionnaire controller

List of files changed

  • test/fixtures/question_types.yml
  • test/fixtures/questionnaires.yml
  • test/fixtures/questions.yml
  • test/functional/questionnaire_controller_test.rb
  • test/unit/author_feedback_questionnaire_test.rb
  • test/unit/metareview_questionnaire_test.rb
  • test/unit/review_questionnaire_test.rb
  • test/unit/teammate_review_questionnaire_test.rb