Quality Best Practices & Toolkit for Enterprise Flex
Presentation given at the French Flex User group : "les tontons flexeurs" on the 21st of July 2009
Author : Xavier Agnetti, François Le Droff (and Alex Ulhmann)
Copyright: Adobe
Quality Best Practices & Toolkit for Enterprise Flex
1. Quality
Best Practices
& Toolkit
for
Enterprise Flex
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
2. Xavier Agnetti
Adobe Consulting
A Flex geek :
leader FlexPMD
Contributeur FlexUnit
conférencier à MAX,
Contact:
xagnetti<at>adobe.com
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
3. François Le Droff
Adobe TXI (Technology & eXperience Innovation)
10 ans (RIA & web 1+n.0)
OSS geek :
membre de
ossgtp, du ParisJUG,
Tontons Flexeurs
contributeur sur qsos, xradar , fna
conférencier à MAX, Solution Linux, Tontons Flexeurs,
BreizhJUG, RiveriaJUG
Contact:
ledroff<at>adobe.com
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
4. François Le Droff
blog : http://www.droff.com
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
5. Et vous ?
Flex ?
FlexUnit ?
Fluint ?
FlexCover ?
FlexMonkey ?
RiaTest ?
Build and CI ?
Ant ?
Maven ?
Hudson ?
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
6. Agenda
Unit Test Best Practice (Alex )
FlexUnit
FlexUnit Demo
Mock
Code Coverage
Functional Test
Load Test
Static Code Analysis
Build
Continuous Integration
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
7. UnitTest
Best Practices
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
8. Our Agile Testing Principles.
Test Everything –
Accept and Minimize
Frameworks, Integration
Untestable Code
etc.
Test Concerns Separately Test Many Things At Once
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
10. Our Agile Testing Principles.
Test First Test Last
Run Tests Continuously One Test Suite Rules Them
All
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
11. State Verification
Exercise
Assert state
Unit test Object under
test
Assert return
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
12. FlexUnit
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
13. Flex Frameworks and Tools: UnitTesting
FlexUnit : http://opensource.adobe.com/wiki/display/flexunit/FlexUnit
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
14. Flex Frameworks and Tools: Unit Testing
FlexUnit
Very similar to JUnit
Event test enabled
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
15. Flex Frameworks and Tools: UnitTesting
FlexUnit Html Reports:
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
16. Flex Frameworks and Tools: UnitTesting
FlexUnit Dashboards:
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
17. Flex Unit Next
Fluint : http://code.google.com/p/fluint/
FlexUnit4 :
http://opensource.adobe.com/wiki/display/flexunit/FlexUnit+4+feature+ov
erview
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
18. Demo FlexUnit
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
20. Demo
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
21. Mock
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
22. Isolating The Object under Test
Production Depended-on Object
Object under Test
Unit Tests Test Double
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
23. Substitution via Dependency Injection (IoC)
public function PolicyPM( policyValidator : IPolicyValidator )
{
}
model = new PolicyPM( new PolicyValidator() );
model = new PolicyPM( new PolicyValidatorDummy() );
Substitution via Dependency Injection
Interface
Domain
Object under Test Interface
Domain Test Double
Interface
®
15
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
24. Behavior Verification Testing What Objects Do Behind the Scenes
Set expected PolicyValidatorMock
behavior
Assert state Exercise
PolicyPMTest
Exercise PolicyPM
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
25. Behavior Verification Testing What Objects Do Behind the Scenes
var mock : PolicyValidatorMock = new
PolicyValidatorMock();
mock.mock.method( “validate” ).withNoArgs.once;
//exercise
var model : PolicyPM = new PolicyPM( mock );
model.next();
mock.mock.verify();
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
26. Our Agile Testing Principles.
State Verification First Behavior Verification
Testing Public API Testing Internal Behavior
Write Test as Code Write Java/AS Docs
Examples
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
27. Making Untestable APIs Testable
Production Code
public class LocalConnectionWrapper extends LocalConnection
implements ILocalConnection
{
}
public interface ILocalConnection extends ISendingLocalConnection,
IReceivingLocalConnection
{
}
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
28. Making Untestable APIs Testable
public interface ISendingLocalConnection extends IEventDispatcher
{
function send( connectionName : String, handler : String, ...args ) : void;
}
public interface IReceivingLocalConnection
{
function set client( value : Object ) : void;
function allowDomain( ...domains ) : void;
function connect( connectionName : String) : void;
function close() : void;
}
®
20
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
29. Substitution via Overriding
Object under Test Untestable behaviour
Test Subclass Substitution
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
30. Substitution via Overriding
Production Code
protected function createReceivingConnection() : IReceivingConnection
{
return new LocalConnectionWrapper();
}
Test Subclass
override protected function createReceivingConnection() :
IReceivingConnection
{
return new LocalConnectionMock();
}
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
31. Substitution via Overriding
var mock : LocalConnectionMock = new LocalConnectionMock();
mock.mock.method( “send” ).withArgs( “connection” ).once;
//exercise
var connector : TestSubclass = new TestSubclass( mock );
connector.go();
mock.mock.verify();
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
32. Mock tooling
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
33. Mock Frameworks
mock-as3: http://code.google.com/p/mock-as3
Used by Adobe Consulting
Mock4AS: http://code.google.com/p/mock4as
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
34. Code Coverage
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
35. Code Coverage Flexcover - Custom Compiler Approach
http://code.google.com/p/flexcover
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
36. Code Coverage Flexcover - Custom Compiler Approach
http://code.google.com/p/flexcover
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
37. Hudson
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
38. Sonar
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
39. Functional Tests
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
40. Flex Frameworks and Tools: Testing
Functional Testing
OS:
Selenium for Flash
FlexMonkey, FunFX
Mercury QTP
IBM Rational Functional Tester
RIATest
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
41. Load/Stress/Endurance
Tests
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
42. Flex Frameworks and Tools: Testing
Load and Stress Testing
JMeter, OpenSTA, Grinder
Other commercial (Flex/AMF specific) products :
NeoLoad
WebLoad
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
43. Static Code Analysis
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
44. Flex Frameworks and Tools: Building : Quality
Quality Reports within your build
AS3NCSS
http://localhost:9999/hudson/job/cairngorm/site/javancss.html
FlexPMD
http://localhost:9999/hudson/job/cairngorm/12/pmdResult/
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
45. Flex PMD
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
46. Demo FlexPMD
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
47. Build
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
48. Flex Frameworks and Tools: Building
Ant :
FlexAntTasks
Ant : Antennae
• Maven :
• Flex-mojos
• Alternatives :
• ServeBox (Projet Français)
• and Israfil
• Archetypes
FlexMojos V3 est un projet sonatype
Sonatype et Adobe travaillent ensemble pour le support FB dans m2eclipse
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
49. Managing Dependencies
Maven (or Ant + Ivy)
Demo : http://localhost:9999/hudson/job/cairngormenterprise/site/dependencies.html
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
50. Managing Dependencies
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
51. Flex Frameworks and Tools: UnitTest within your Build
FlexUnit within your build
Maven
FlexMojos V3 est un projet sonatype
Sonatype et Adobe travaillent ensemble pour le
support FB dans m2eclipse
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
52. FlexPMD within your build
Maven
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
53. CI
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
54. Flex Frameworks and Tools: Building and CC
Quality within your build : CC
Demo : http://localhost:9999/hudson/
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
55. Des questions ?
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.