CSC/ECE 517 Fall 2015 E1590 Integration testing for Team creation: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(47 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== '''Purpose''' ==
== '''Purpose''' ==
This project is to perform integration testing for team creation. The testing needs to be done with the help of RSpec and Capybara. The UI procedures need to be tested are:
This project is to perform integration testing for team creation. The testing needs to be done with the help of RSpec and Capybara. The UI procedures need to be tested are:
* Log in
* Log in as a student
* Create a course
* Choose a available topic
* View scores for an assignment
* Invite one or more students as teammates
* View review scores (“review report”)
* Students who get the invition could accept or denial
* View author-feedback scores
* After accept the invitation, the team should form and all teammates should have same topic
* Create an assignment
** 2 rounds of review
** Has no topics / has topics
** Staggered-deadline assignments


== '''Testing Tools and Concepts''' ==


== '''Background''' ==
=== RSpec ===
Rspec <ref>[https://en.wikipedia.org/wiki/RSpec RSpec Wiki Page]</ref> is a behavior-driven development (BDD) framework for the Ruby programming language, inspired by JBehave. It contains its own mocking framework that is fully integrated into the framework based upon JMock. The framework can be considered a domain-specific language (DSL) and resembles a natural language specification.In this project we will use expectation part of RSpec at most time.
 
; RSpec-expectations<ref>[https://github.com/rspec/rspec-expectations RSpec expectations page]</ref>
: RSpec::Expectations lets you express expected outcomes on an object in an example
 
; RSpec-rails<ref>[https://github.com/rspec/rspec-rails RSpec rails page]</ref>
: RSpec-rails is a testing framework for Rails 3.x and 4.x..
 
=== Capybara ===
Capybara is a library written in the Ruby programming language which makes it easy to simulate how a user interacts with application. Capybara can talk with many different drivers which execute tests through the same clean and simple interface.<ref>[http://www.gamesparks.com/blog/automated-testing-with-cucumber-and-capybara/ Capybara page]</ref>Capybara helps developer test web applications by simulating how a real user would interact with app.<ref>[https://github.com/jnicklas/capybara Capybara github page]</ref>
 
* Using Capybara with Cucumber:


=== RSpec ===
<code> cucumber-rails gem </code> comes with Capybara support built-in
Rspec <ref>[https://en.wikipedia.org/wiki/RSpec RSpec Wiki Page]</ref> is a Behavior Driven Development (BDD) framework for Ruby. It is composed of 4 main parts <ref>[http://rspec.info/ RSpec Official Website]</ref>:
; rspec-core
: The spec runner, providing a rich command line program, flexible and customizable reporting, and an API to organize your code examples.


An example of running rspec file in terminal: <code>rspec spec/model_spec.rb </code>
* Using Capybara with RSpec:


; rspec-expectations
Load RSpec 2.x support by adding the line: <code> require 'capybara/rspec' </code>.
: Provides a readable API to express expected outcomes of a code example.


; rspec-mocks
* Using Capybara with Test::Unit:
: Test double framework, providing multiple types of fake objects to allow you to tightly control the environment in which your specs run.


; rspec-rails
When using Rails, add the following code in <code> test_helper.rb </code> file to make Capybara available in all test cases deriving from <code>ActionDispatch::IntegrationTest </code>.
: Supports using RSpec to test Ruby on Rails applications in place of Rails' built-in test framework.


=== Capybara ===
<code> class ActionDispatch::IntegrationTest </code>
Capybara is a web-based automation test tool that simulates a real user to follow the scenarios of user stories.<ref>[https://github.com/jnicklas/capybara Capybara on GitHub]</ref> It could interact with app to receive pages, parse the HTML and submit forms as a user would.<ref>[https://www.youtube.com/watch?v=p7ZcZNuZ0aw Introducing cucumber & capybara on YouTube]</ref> Used with RSpec and Ruby on Rails (version 1.9 or later), capybara makes it easier to write integration tests. <ref>[http://techiferous.com/2010/04/using-capybara-in-rails-3/ Using Capybara in Rails 3]</ref> It is used on the top of an underlying web-based driver and offers a user-friendly DSL (Domain Specific Language) to describe actions executed by the underlying web driver. Such as <code>rack::test</code>, <code>selenium-webdriver</code> and <code>capybara-webkit</code>.<ref>[http://www.sitepoint.com/basics-capybara-improving-tests/ The Basics of Capybara and Improving Your Tests]</ref>
    <code> # Make the Capybara DSL available in all integration tests </code>
    <code> include Capybara::DSL </code>
<code> end </code>


In this project, we use capybara with rspec by adding the following line:
<code> require 'capybara/rspec' </code>
Then put capybara specs in <code>spec/features</code>.
=== Integration test ===
=== Integration test ===
Integration test is a software testing definition that we combine modules then test them as one group. It is an important application testing way. It is always adapted after unit testing, we need to combine different units to test the functionalities and verify that the aggregated group could deliver its output properly. The purpose of integration test is to verify the functionality of interface between interacted parts, also we can know performance of the subsystems. The integration testing has two types, big bang top down and bottom up.
Integration testing<ref>[https://msdn.microsoft.com/en-us/library/aa292128(v=vs.71).aspx Integration test]</ref> is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component. A component, in this time, refers to an integrated aggregate of more than one unit. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups.
* '''Big Bang for Integration test '''


* '''Big Bang'''
Big Bang<ref>[http://www.tutorialspoint.com/software_testing_dictionary/big_bang_testing.htm Big Bang]</ref> Integration Testing is an integration testing strategy wherein all units are linked at once, resulting in a complete system. When this type of testing strategy is adopted, it is difficult to isolate any errors found, because attention is not paid to verifying the interfaces across individual units.


In this type, since all the application is combined with all major usage modules. So we test them under usage model testing, which means we can simulate the users' acts under testing environment. When doing this, we can test if all the expected components is got when we actually do the same way under production environment. It is an effective way to test the functionalities and got better coverage since we are creating the realistic scenarios. It will make sure the application can have proper output when a user does the same input.
* '''Two apporachs: Top down and Bottom up'''


* '''Top down and Bottom up'''
•The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.


Top down and bottom up is another type of integration testing. For top down, we test the top integrated module firstly and test the ranch of it again and again, then we can test all the related modules finally. For Bottom up way, we test the most basic module at first and check the module that containing this basic module. The advantage of it is that we can find the bug easier because we will not miss any branch that we use. However, it is time consuming in this way.<ref>[https://en.wikipedia.org/wiki/Integration_testing/ Integration testing on Wikipedia]</ref>
•The bottom-up approach requires the lowest-level units be tested and integrated first. These units are frequently referred to as utility modules. By using this approach, utility modules are tested early in the development process and the need for stubs is minimized. The downside, however, is that the need for drivers complicates test management and high-level logic and data flow are tested late. Like the top-down approach, the bottom-up approach also provides poor support for early release of limited functionality.


== '''Testing Plan''' ==
Based on the project requirements, the testing can be divided into the following parts:
T1. Ensure a student is able to login to the system.
T2. Ensure a student is able to choose a topic from the assignment.


== '''Testing''' ==
T3. Ensure a student is able to form a team by inviting other students enrolled in this course.
    S1. If the invitation is sent to a student who isn't enrolled in the class, it should not be allowed.
    S2. If the invitation is sent to a student who is enrolled in the class, it should be allowed.
T4. Ensure an invitee is able to accept or reject.
   
T5. Ensure all teammates have the same topic.
    S1. If a student accepts the invitation and the student have a topic before, the topic should be dropped.
    S2. If a student accepts the invitation and did not have the topic before, the student should have the same topic as other teammates who accepted the invitation.


Based on the project requirements, the testing can be divided into the following parts:
== '''Modifying factories''' ==
Factory_girl<ref>[https://github.com/thoughtbot/factory_girl]</ref> is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance.
The file listed below is used for modifying factories for test.
* /expertiza/spec/factories/factories.rb
 
Using factory_girl to modify course data.
 
  factory :course ,class:Course do
    name "CSC 517 Fall 2009"
    instructor_id nil
    directory_path "csc517/f09"
    info "Object-Oriented Languages and Systems"
    private true
    institutions_id nil
end
 
Using factory_girl to modify assignment data.


T1. Ensure an instructor is able to login to the system.
  factory :assignment ,class:Assignment do
    name "final2"
    directory_path "try"
    submitter_count 0
    course
    instructor_id nil
    private false
    num_reviews 0
    num_review_of_reviews 0
    num_review_of_reviewers 0
    review_questionnaire_id nil
    review_of_review_questionnaire_id nil
    teammate_review_questionnaire_id nil
    reviews_visible_to_all false
    association  :wiki_type ,:factory => :wikitype
    num_reviewers 0
    spec_location "bfbfb"
    author_feedback_questionnaire_id nil
    max_team_size 3
    ...
  end


T2. Ensure an instuctor is able to create a course.
Using factory_girl to set due date.


T3. Ensure that the score of a certain assignment can be viewed.
  factory :due_date ,class:DueDate do
    due_at  "2015-12-30 23:30:12"
    association :deadline_type, :factory => :deadline_type,strategy: :build
    assignment { Assignment.first || association(:assignment)} 
    submission_allowed_id nil
    review_allowed_id  nil
    resubmission_allowed_id  nil
    rereview_allowed_id  nil
    review_of_review_allowed_id  nil
    round  1
    flag  false
    threshold  1
    delayed_job_id  nil
    deadline_name  nil
    description_url nil
    quiz_allowed_id nil
    teammate_review_allowed_id nil
  end


T4. Ensure to view the score of a review.
== '''Scenario''' ==
[[File:5190_diagram1.jpg]]


T5. Ensure to view the score of an author feedback.
== '''Testing Scenario''' ==
Using Capybara to test expertize by simulating how a real user would do to form or join a team.
The file listed below is used for simulating uses` behavior.
* /expertiza/spec/features/team_creation_spec.rb


T6. Ensure to create an assignment which has two rounds of review, has a topic or does not has a topic, and has a staggered-deadline.
Simulating one student creates a team and send an invitation to another student, and the other one accept this.


  it 'one student should send invitation and the other student should accept' do
  student=User.find_by_name("student2064") 
  role=student.role
  ApplicationController.any_instance.stub(:current_user).and_return(student)
  ApplicationController.any_instance.stub(:current_role_name).and_return('Student')
  ApplicationController.any_instance.stub(:current_role).and_return(role)
  visit '/student_task/list'
  expect(page).to have_content('final2')
  click_link 'final2'
  expect(page).to have_content('Submit or Review work for final2')
  click_link 'Signup sheet'
  expect(page).to have_content('Signup sheet for final2 assignment')
  visit '/sign_up_sheet/sign_up?assignment_id=1&id=1'
  expect(page).to have_content('Your topic(s)')
  visit '/student_task/list'
  expect(page).to have_content('final2')
  click_link 'final2'
  click_link 'Your team'
  expect(page).to have_content('final2_Team1')
  fill_in 'user_name', with:'student2065'
  click_button 'Invite'
  expect(page).to have_content('student2065')
  student=User.find_by_name("student2065") 
  role=student.role
  ApplicationController.any_instance.stub(:current_user).and_return(student)
  ApplicationController.any_instance.stub(:current_role_name).and_return('Student')
  ApplicationController.any_instance.stub(:current_role).and_return(role)
  visit '/student_task/list'
  expect(page).to have_content('final2')
  click_link 'final2'
  click_link 'Your team'
  #expect(page).to have_content('student2064')
  visit '/invitation/accept?inv_id=1&student_id=1&team_id=0'
  expect(page).to have_content('Team Name: final2_Team1')


=References=
=References=
<references></references>
<references></references>

Latest revision as of 03:29, 5 December 2015

Purpose

This project is to perform integration testing for team creation. The testing needs to be done with the help of RSpec and Capybara. The UI procedures need to be tested are:

  • Log in as a student
  • Choose a available topic
  • Invite one or more students as teammates
  • Students who get the invition could accept or denial
  • After accept the invitation, the team should form and all teammates should have same topic

Testing Tools and Concepts

RSpec

Rspec <ref>RSpec Wiki Page</ref> is a behavior-driven development (BDD) framework for the Ruby programming language, inspired by JBehave. It contains its own mocking framework that is fully integrated into the framework based upon JMock. The framework can be considered a domain-specific language (DSL) and resembles a natural language specification.In this project we will use expectation part of RSpec at most time.

RSpec-expectations<ref>RSpec expectations page</ref>
RSpec::Expectations lets you express expected outcomes on an object in an example
RSpec-rails<ref>RSpec rails page</ref>
RSpec-rails is a testing framework for Rails 3.x and 4.x..

Capybara

Capybara is a library written in the Ruby programming language which makes it easy to simulate how a user interacts with application. Capybara can talk with many different drivers which execute tests through the same clean and simple interface.<ref>Capybara page</ref>Capybara helps developer test web applications by simulating how a real user would interact with app.<ref>Capybara github page</ref>

  • Using Capybara with Cucumber:

cucumber-rails gem comes with Capybara support built-in

  • Using Capybara with RSpec:

Load RSpec 2.x support by adding the line: require 'capybara/rspec' .

  • Using Capybara with Test::Unit:

When using Rails, add the following code in test_helper.rb file to make Capybara available in all test cases deriving from ActionDispatch::IntegrationTest .

 class ActionDispatch::IntegrationTest 
    # Make the Capybara DSL available in all integration tests 
    include Capybara::DSL 
 end 

Integration test

Integration testing<ref>Integration test</ref> is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component. A component, in this time, refers to an integrated aggregate of more than one unit. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups.

  • Big Bang for Integration test

Big Bang<ref>Big Bang</ref> Integration Testing is an integration testing strategy wherein all units are linked at once, resulting in a complete system. When this type of testing strategy is adopted, it is difficult to isolate any errors found, because attention is not paid to verifying the interfaces across individual units.

  • Two apporachs: Top down and Bottom up

•The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.

•The bottom-up approach requires the lowest-level units be tested and integrated first. These units are frequently referred to as utility modules. By using this approach, utility modules are tested early in the development process and the need for stubs is minimized. The downside, however, is that the need for drivers complicates test management and high-level logic and data flow are tested late. Like the top-down approach, the bottom-up approach also provides poor support for early release of limited functionality.

Testing Plan

Based on the project requirements, the testing can be divided into the following parts:

T1. Ensure a student is able to login to the system.

T2. Ensure a student is able to choose a topic from the assignment.

T3. Ensure a student is able to form a team by inviting other students enrolled in this course.

   S1. If the invitation is sent to a student who isn't enrolled in the class, it should not be allowed.
   S2. If the invitation is sent to a student who is enrolled in the class, it should be allowed.

T4. Ensure an invitee is able to accept or reject.

T5. Ensure all teammates have the same topic.

   S1. If a student accepts the invitation and the student have a topic before, the topic should be dropped.
   S2. If a student accepts the invitation and did not have the topic before, the student should have the same topic as other teammates who accepted the invitation.

Modifying factories

Factory_girl<ref>[1]</ref> is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance. The file listed below is used for modifying factories for test.

  • /expertiza/spec/factories/factories.rb

Using factory_girl to modify course data.

 factory :course ,class:Course do
   name "CSC 517 Fall 2009"
   instructor_id nil
   directory_path "csc517/f09"
   info "Object-Oriented Languages and Systems"
   private true
   institutions_id nil
end

Using factory_girl to modify assignment data.

 factory :assignment ,class:Assignment do
   name "final2"
   directory_path "try" 
   submitter_count 0 
   course
   instructor_id nil
   private false
   num_reviews 0
   num_review_of_reviews 0
   num_review_of_reviewers 0
   review_questionnaire_id nil
   review_of_review_questionnaire_id nil
   teammate_review_questionnaire_id nil
   reviews_visible_to_all false
   association  :wiki_type ,:factory => :wikitype
   num_reviewers 0
   spec_location "bfbfb"
   author_feedback_questionnaire_id nil
   max_team_size 3
   ...
 end

Using factory_girl to set due date.

 factory :due_date ,class:DueDate do
   due_at  "2015-12-30 23:30:12"
   association :deadline_type, :factory => :deadline_type,strategy: :build 
   assignment { Assignment.first || association(:assignment)}   
   submission_allowed_id nil
   review_allowed_id  nil
   resubmission_allowed_id  nil
   rereview_allowed_id  nil
   review_of_review_allowed_id  nil
   round  1
   flag  false
   threshold  1
   delayed_job_id  nil
   deadline_name  nil
   description_url nil
   quiz_allowed_id nil
   teammate_review_allowed_id nil
 end

Scenario

Testing Scenario

Using Capybara to test expertize by simulating how a real user would do to form or join a team. The file listed below is used for simulating uses` behavior.

  • /expertiza/spec/features/team_creation_spec.rb

Simulating one student creates a team and send an invitation to another student, and the other one accept this.

 it 'one student should send invitation and the other student should accept' do
 student=User.find_by_name("student2064")  
 role=student.role
 ApplicationController.any_instance.stub(:current_user).and_return(student)
 ApplicationController.any_instance.stub(:current_role_name).and_return('Student')
 ApplicationController.any_instance.stub(:current_role).and_return(role)
 visit '/student_task/list'
 expect(page).to have_content('final2')
 click_link 'final2'
 expect(page).to have_content('Submit or Review work for final2')
 click_link 'Signup sheet'
 expect(page).to have_content('Signup sheet for final2 assignment')
 visit '/sign_up_sheet/sign_up?assignment_id=1&id=1'
 expect(page).to have_content('Your topic(s)')
 visit '/student_task/list'
 expect(page).to have_content('final2')
 click_link 'final2'
 click_link 'Your team'
 expect(page).to have_content('final2_Team1')
 fill_in 'user_name', with:'student2065'
 click_button 'Invite'
 expect(page).to have_content('student2065') 
 student=User.find_by_name("student2065")  
 role=student.role
 ApplicationController.any_instance.stub(:current_user).and_return(student)
 ApplicationController.any_instance.stub(:current_role_name).and_return('Student')
 ApplicationController.any_instance.stub(:current_role).and_return(role)
 visit '/student_task/list'
 expect(page).to have_content('final2')
 click_link 'final2'
 click_link 'Your team'
 #expect(page).to have_content('student2064') 
 visit '/invitation/accept?inv_id=1&student_id=1&team_id=0'
 expect(page).to have_content('Team Name: final2_Team1')

References

<references></references>