Archive for December, 2006
SAP Enterprise Portal + Automated Functional Testing – Part 7 of …
In anticipation of posting about a new topic I’m going to wrap up my Watir Automated testing posts with a few more top tips.
TOP TIP – How do I run a single test?
So you have lots of tests in your test suite but only want to run one? No need to create an ad-hoc test case, simply pass in the –name parameter when running the test:
ruby test_mytestcase.rb --name test_just_this_method
TOP TIP – How do I run the test in background mode?
Running the test so you can see what is going on in the browser is sometimes useful but most of the time you’ll want to run the tests in the background and just see the results. This is easily done by passing the -b parameter on the command line:
ruby test_mytestcase.rb -b
TOP TIP – Helper methods
I have a couple of helper methods which I use in most of my test cases:
def should_find(find_me)
assert(@ie.contains_text(find_me), "*\n*\n*\nText not found: #{find_me}\n*\n*\n*")
end
def should_not_find(find_me)
assert_nil(@ie.contains_text(find_me), "*\n*\n*\nFound text which should not be present: #{find_me}\n*\n*\n*")
end
No clever code here it just means I can write tests which are easier to read:
should_not_find("Portal Runtime Error")
should_find("Success")
FIN
Well I’m running out of content about testing as you can probably tell! So I guess that’s a wrap. I’ll no doubt re-visit automated testing again at some point but for now that’s my lot.
NEXT TIME
I’ve been working on creating web services for Enterprise Portal and calling those web services from Microsoft .Net. I’ve taken lots of notes, so expect a series of EP web services posts real soon.
SAP Portal Developer Guide
Looking for help on the SAP Portal? HTMLB syntax and lots of other goodies this way…
SAP Portal how do I reference a Javascript file?
Easy when you know how
request = (IPortalComponentRequest)this.getRequest(); response = (IPortalComponentResponse)this.getResponse(); IResource jsResource = request.getResource(IResource.SCRIPT, “scripts/myscript.js”); response.addResource(jsResource);
Ruby unit testing – run only one test
If you don’t wish to run all the unit tests in your test case you can tell ruby to run only one by passing in the name of the test:
ruby test_mytestcase.rb --name test_just_this_method
Ruby testing – setup project folders
Its a good idea to keep your test cases seperate from your production code:
myproject
lib/
workomatic.rb
test/
test_workomatic.rb
When you have your project setup in this way add the following line to the top of your test cases:
Inside test_workomatic.rb
$:.unshift File.join(File.dirname(__FILE__), "..", "lib") require workomatic.rb
Location of XML files
http://YOURSERVERNAME:50000/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/
documents\portalResource\USER.R3_DATASOURCE.
Castle Monorail + Active Record + Testing + CreateSchemaFromFile
It’s always a good idea to have your test database match your production database exactly to do that use:
ActiveRecordStarter.CreateSchemaFromFile()
Unlike CreateSchema which takes a best guess at how your schema should be CreateSchemaFromFile uses an SQL script which allows you to control exactly what the schema should be.
Call CreateSchemaFromFile as part of your PrepareSchema method in your AbstractTestCase class.
protected virtual void PrepareSchema()
{
// If you want to delete everything from the model.
// Remember to do it in a descendent dependency order
// Office.DeleteAll();
// User.DeleteAll();
// Another approach is to always recreate the schema
// (please use a separate test database if you want to do that)
ActiveRecordStarter.DropSchema();
ActiveRecordStarter.CreateSchemaFromFile("schema.sql");
}
Your schema.sql file should contain scripts in the standard MS SQL format:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Application_Status]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Application_Status]
GO
CREATE TABLE [dbo].[Application_Status] (
[ID] [int] NOT NULL ,
[Title] [varchar] (50) NOT NULL ,
[Description] [text] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO