Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
by Camptocamp SA
V0.2 du 09.03.2010
Open Source Base Camp
Table of content
1 Purpose of the document ........................................................................................... 3
1.1 Purpose......................................................................................................................... 3
1.2 Contact.......................................................................................................................... 3
1.3 Reviews......................................................................................................................... 3
2 Introduction.................................................................................................................. 4
2.1 What is OERPScenario ?...............................................................................................4
2.2 When to use OERPScenario?........................................................................................4
2.3 Why use OERPScenario?..............................................................................................5
2.4 The components of OERPScenario............................................................................... 6
2.5 How is it built ?...............................................................................................................6
3 Install and configure OERPScenario.......................................................................... 7
3.1 Install libraries and dependencies ................................................................................. 7
3.2 Get OERPScenario........................................................................................................ 7
3.3 How to configure it?....................................................................................................... 8
4 Running OERPScenario.............................................................................................. 9
4.1 Using simple tag............................................................................................................ 9
4.2 Advanced usage with tags and names...........................................................................9
4.3 Using the rake file........................................................................................................ 10
4.4 Output format............................................................................................................... 10
5 Writing a scenario : for business individuals..........................................................11
5.1 The Gherkin Syntax......................................................................................................11
5.2 Feature introduction..................................................................................................... 12
5.3 How to describe a test case?....................................................................................... 12
5.4 Where should I contribute to test writing?.................................................................... 12
6 Coding a Scenario : for technical individuals..........................................................13
6.1 Your first scenario........................................................................................................ 13
7 Technical docs........................................................................................................... 15
7.1 Using Helpers.............................................................................................................. 15
7.2 Using the Memorizer.................................................................................................... 16
7.3 Create an invoice and use workflow.............................................................................17
7.4 Use the Ruby console.................................................................................................. 17
7.5 Folder and files structures............................................................................................18
7.6 The Ooor and Cucumber doc.......................................................................................19
7.7 The Rdoc of OERPScenario........................................................................................ 19
1.1 Purpose
This document addresses the usage of OERPScenario, allowing to write business oriented
test cases in OpenERP. Parts of this text are excerpts from:
http://wiki.github.com/aslakhellesoy/cucumber/
This document is released under «Creative Commons»; the jurisdiction's law and
conditions are available here: http://creativecommons.org/licenses/by-sa/2.5/ch (or by mail
at Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105,
USA).
1.2 Contact
For any information, please contact:
Name Joël Grand-Guillaume
Title Camptocamp SA
Email openerp@camptocamp.com
Project OERPScenario
1.3 Reviews
Date Version Authors(s) Notes
07.10.09 0.1 JGE Initial version
03.09.10 0.2 SDE Editing
2 Introduction
OERPScenario allows business individuals to write a business scenario for a specific use
case and then allows technical individuals to parse the sentences to code the test case.
OERPScenario can address all OpenERP features and processes, use the demo data and
run the quality tests provided by the editor, OpenERP SA.
Once it's done, go into the OERPScenario folder and run the following command to test the
connexion:
rake compile
As the tests are running under a specific user, you can always change the one that has
been set-up as default (by default, all tests are running with the user defined in the config
file). If you need to run the tests under another user, edit the following file:
« /features/_basic/_init.feature » and change the sentence according to your needs:
Given I am logged as admin user with password admin used → Given I am logged as
administrator user with password 12345 used
The configuration is done!
4 Running OERPScenario
You can launch the test suite from the OERPScenario folder with the following commands:
cucumber feature --tag=@account
This will execute all scenarios related to the OpenERP account module (notice that tags
can be set on features or scenarios). The feature tags are true for all included scenarios,
where the scenario tags are true only for the current scenario.
Usually, running feature tags is enough, as they launch all included scenarios.
Using 'OR' between tags (run all scenarios matching the given tags):
cucumber feature –tag=@init,@account
Using 'NOT' on a tag (run all scenarios except the given tags)
cucumber feature –tag=~@base
The format option also allows you to print out various information while running tests, like
the line number of the step_definition for example.
First line starts the feature. Lines 2-4 are unparsed text, which is expected to describe the
business value of this feature. Line 6 starts a scenario. Lines 7-13 are the steps for the
scenario. Line 15 starts next scenario and so on.
For each step, Cucumber will look for a matching step definition. A step definition is written
in Ruby and can parse part of the step words with regular expressions to perform the test.
Once you save the file, run OERPScenario with the following command:
cucumber features --tag=@sample_test
This will run the background first (as it is for every scenario), then your new test.
No steps exists for the specified sentence, so OERPScenario ask you to define it, informing
how it should parse and execute the action you described.
You can implement step definitions for undefined steps with these snippets:
Given /^I want to show you how to use OERPScenario$/ do
pending # express the regexp above with the code you wish you had
end
When /^I create a partner named automatedtest$/ do
pending # express the regexp above with the code you wish you had
end
Then /^I should be able to find it by his id$/ do
pending # express the regexp above with the code you wish you had
end
Then /^the name should be automatedtest$/ do
pending # express the regexp above with the code you wish you had
end
Copy these lines and paste them in a new created text file called « sample_step.rb » into
the « step_definitions » folder.
For the first sentence, we expect nothing special to be done, so just remove the pending
keyword and let this step empty.
For the second sentence, we want to create a partner called automatedtest; change it with :
When /^I create a partner named (\w+)$/ do |name|
This will take all the text after « named » and put it into the name variable. Then write that
into the step:
1. # Create a new partner using Ooor, and store it in a
2. # global var for the current feature
3. @partner = ResPartner.new(:name => name)
4. @partner.create
5. # Controle it has been a success
6. @partner.should be_true
You can now run OERPScenario with the tag @sample_test, and every step should pass.
Find the complete example in the « samples » folder.
7 Technical docs
The best technical documentation will probably be the already coded test cases. Because
all operations are explicitly written in the test case description, you will easily understand
what the code found in the step represents. Below you will find some advices to help you
get the basic concept.
From here, you can type any command you want. Try this one to get a nonexistent field
from ResPartner model. Ooor will even return you what is accessible:
a=ResPartner.find(:first)
a.x
Test everything you need through this console. It is recommended to take a look at the
Ooor documentation to know more about ActiveRessource on OpenObject:
http://github.com/rvalyi/ooor