CSC/ECE 517 Spring 2014/oss E1414 st: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 32: Line 32:
* remove all members belonging to an item
* remove all members belonging to an item


== Motivation ==
== Background ==
There were no functional tests written on the two controllers to detect bugs, as well as confirming they are functional by itself and after integration.


Our goal is to add comprehensive functional tests and integration tests to the two controllers to provide a preferable test suite for the future developers.  
=== teams_users.rb & teams_users_controller.rb===
 
* Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.
Also, as the classes are influenced by the changes from other, we are also responsible for fixing some of the bugs, refactoring the method names to a better ones, as well as reporting the bugs found in the testing process.
* There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.


== Tasks ==
== Tasks ==

Revision as of 18:29, 9 April 2014

E1414: Testing classes related to teams

Please be advised that we do not have deployment link, since our work are all back-end tests

Classes

app/controllers/teams_controller.rb

teams_controller contains functionalities for team management for instructor/TA accounts. Instructor/TA can:

  • view current teams
  • create new teams
  • import/export teams
  • delete all teams/delete specified team
  • copy existing teams from a course down to an assignment(inherit)
  • update team's information

app/controllers/student_team_controller.rb

The student_team_controller support team management for student account. student can

  • create team
  • view current team (including team invitations received and sent)
  • advertise for their team
  • remove the advertise for their team
  • leave the team

app/controllers/teams_users_controller.rb

The teams_users_controller support team member management for instructor/TA accounts Instruction/TA can:

  • get a user name by inputting part of the name
  • list team members of a team
  • add a user to a team
  • remove a team member from a team
  • remove all members belonging to an item

Background

teams_users.rb & teams_users_controller.rb

  • Teams_users.rb and teams_users_controller.rb are used for Instructor/TA to manage the members of teams.
  • There is no functional test for teams_users_controller.rb and unit test for teams_users.rb in the current version of expertiza codes.

Tasks

Overall: contribute to the code coverage, ideally having overall coverage increase 2%

student_team_controller

  • write tests
  • def advertise_for_partners # change to “advertise”
  • def remove # change to “remove_advertisment”
  • def review # remove this method

teams_controller

  • write tests

Deployment

Please note that all of our work will be under the /test folder, which means they will not show any change on the view. To see the result of tests, run

rake test TEST=test/functional/student_team_controller.rb

and

rake test TEST=test/functional/teams_controller

running the whole test suite with rake test is not recommended, as the schema change overtime has broke some of the previous tests.

Testing

Framework
Rails default test framework
Sample data
Fixtures (under /test/fixtures)
Coverage tool
SimpleCov
Total Number of Tests
37
Previous Coverage
22.32%
Current Coverage
24.08%

Testing Scenarios

student_team_controller

Most of the test case are straightforward. There are some of the test cases was commented out due to bug in the controller

  • View student team (GET #view)
  • Edit team (GET #edit)
  • Create team with valid name (POST #create)
  • Create team with name in use (POST #create)
  • Update valid team name (POST #update)
  • Update team name in use (POST #update)
  • Update with current team name (POST #update)
  • Advertise (GET #advertise)

This is currently commented out in the committed code. It seems like the method is never called. It raises missing template error upon every call. The advertise method was previously named advertise_for_partners, but renamed due to ambiguity as there is another class with the same name.

  • Remove advertisement (GET #remove_advertisement )

The remove_advertisement method was previously named remove, but renamed to avoid ambiguity This method is never called as well, but it is functional as it do not require any template.

  • Leave student team (GET #leave)

This is currently commented out in the committed code, because it will raise error every time when called. It seems like problem happens on

 line 96: other_members = TeamsUser.where( ['team_id = ?', params[:team_id]]).first
 line 97: if other_members.length == 0

This will raise error due to the calling length of other_members, which is a single object but not an array. Also, the related record seems to be remain undeleted in the database.

teams_controller

Current test cases are as following.

  • Create team should increase the number of teams by 1(GET #create)
  • Create team should increase the number of team nodes by 1(GET #create)
  • Create team with existing name (POST #create)
  • Create team should redirect to list assignments (POST #create)
  • Delete all teams (GET #delete_all)
  • Delete all teams should redirect to list (GET #delete_all)
  • List should receive assignment (GET #list)
  • List should receive course (GET #list)
  • New should assign parent (GET #new)
  • Update team should redirect (POST #update)
  • Update team should have validate name (POST #update)
  • Edit team should have time (POST #edit)
  • Delete team should redirect (POST #delete)
  • Delete team should decrease the number of teams by 1(GET #delete)
  • Delete team should decrease the number of team nodes by 1(GET #delete)
  • Inherit team should redirect (POST #inherit)
  • Bequeath team should redirect (POST #bequeath)

The methods in the following are ignored in testing since they are never used in current codes.

  • create_teams_view
  • create_teams

Sample Test Code

We show two pieces of test code for two controllers to explain how our test works

   test "create_student team with name in use" do
       sessionVars = session_for(users(:student8))
       post(:create, {'team' => { 'name' => 'IntelligentTeam2'}, 'id' => participants(:par21).id, "commit" => "Create Team"}, sessionVars, nil)
       assert_equal 'Team name is already in use.', flash[:notice]
       assert_redirected_to :controller => 'student_team', :action => 'view', :id => participants(:par21).id
   end
   test "create_should_increase_number_of_teams_course" do
       sessionVars = session_for(users(:instructor1))
       sessionVars[:team_type] = "Course"
       assert_difference 'Team.count' do
         get :create, {'id' => @testCourse,'team' => {'name' => "Random"}},sessionVars
       end
   end

The first piece of code is from student_team_controller.rb. It tests if there is already a same team name when student8 want to create a team. The second piece of code is from teams_controller_test.rb. It tests if the team number decreases when instructor1 creates a new team for a course.

As we can see from the code, when we want to use post or get, several parameters are needed. Usually we use four parameters: First, the method we are requesting. Second, an hash of request parameters for the method. Third, an optional hash of session variables. Forth, an optional hash of flash values. If we do not want to pass in the optional hash, we can set it to nil as the first piece of code shows, or we can just leave it blank as the second piece of code shows.

When we run the command rake test TEST=test/functional/your_test_file.rb, you will see if the test is passed or not.

Result

Future Works

student_team_controller

Please note that this bug was reported fixed in the newest version of master branch of expertiza, but the fix came too late

There are several error raised from leave method need to be fixed, as mentioned above. Future teams may need to add tests on it as soon as it fixed, since it is a crucial functionality of the student team.

Also, methods that seems like not being used, such as advertise and remove_advertisement may need to be double checked and see if they are redundant.

teams_controller

The method create_teams_view does not be used at all. So it is safe to delete it.

The method create_teams calls the method randomize_all_by_parent, which is not correct. The developer may want to fix these bugs.

It's possible that we can write more testing cases if we improve the fixture.

References

<references/>