Www.cfunited.com Unit and Functional Testing Your Flex Applications Mike Nimer Dir. Of Engineering nomee.com.

Slides:



Advertisements
Similar presentations
Christian Hujer What is AceUnit? How does AceUnit work? How do I use AceUnit? © 2007 Christian Hujer.
Advertisements

MAHDI OMAR JUNIT TUTORIAL. CONTENTS Installation of Junit Eclipse support for Junit Using Junit exercise JUnit options Questions Links and Literature.
Prashant Lambat Sr. Manager SQA Engineering Symantec Corporation, Pune Date: 29 th January 2011.
Test Automation Framework Ashesh Jain 2007EE50403 Manager Amit Maheshwari.
Well-behaved objects 4.0 Testing. 2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main concepts to.
Program Testing Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
24-Jun-15 JUnit. 2 Test suites Obviously you have to test your code to get it working in the first place You can do ad hoc testing (running whatever tests.
TDD Test-Driven Development. JUnit 4.0 To use annotations need to import org.junit.Test To use assertion need to import org.junit.Assert.* No need to.
Writing a Unit test Using JUnit At the top of the file include: import junit.framework.TestCase; The main class of the file must be: public Must extend.
 What is Software Testing  Terminologies used in Software testing  Types of Testing  What is Manual Testing  Types of Manual Testing  Process that.
Software testing techniques Automated software testing Presentation on the seminar Kaunas University of Technology.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
Test Driven Development TDD. Testing ”Testing can never demonstrate the absence of errors in software, only their presence” Edsger W. Dijkstra (but it.
© Dr. A. Williams, Fall Present Software Quality Assurance – JUnit Lab 1 JUnit A unit test framework for Java –Authors: Erich Gamma, Kent Beck Objective:
Lecture 6 Software Testing and jUnit CS140 Dick Steflik.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 23 Slide 1 Software testing Slightly adapted by Anders Børjesson.
© 2012 IBM Corporation Rational Insight | Back to Basis Series Chao Zhang Unit Testing.
Principles of Object Oriented Programming Practical session 2 – part A.
Programming. What is a Program ? Sets of instructions that get the computer to do something Instructions are translated, eventually, to machine language.
Testing in Extreme Programming
Capture and Replay Often used for regression test development –Tool used to capture interactions with the system under test. –Inputs must be captured;
Sadegh Aliakbary Sharif University of Technology Spring 2012.
Continuous QA Sewit Adams (Colorado State University) Bin Gao (Michigan State University) Jerry Neal (Indiana University)
CSE 219 Computer Science III Testing. Testing vs. Debugging Testing: Create and use scenarios which reveal incorrect behaviors –Design of test cases:
Software Development Software Testing. Testing Definitions There are many tests going under various names. The following is a general list to get a feel.
Test Driven Development Arrange, Act, Assert… Awesome Jason Offutt Software Engineer Central Christian Church
Computer Concepts 2014 Chapter 12 Computer Programming.
Dr. Tom WayCSC Testing and Test-Driven Development CSC 4700 Software Engineering Based on Sommerville slides.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
Distributed Java Programming Distributed Java Programming Setting up a Java Development Environment.
TEST-1 6. Testing & Refactoring. TEST-2 How we create classes? We think about what a class must do We focus on its implementation We write fields We write.
Introduction to JUnit 3.8 SEG 3203 Winter ‘07 Prepared By Samia Niamatullah.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional.
Testing, Testing & Testing - By M.D.ACHARYA QA doesn't make software but makes it better.
JUnit Don Braffitt Updated: 10-Jun-2011.
Selenium January Selenium course content  Introduction (Session-1)Session-  Automation  What is automation testing  When to go for automation.
Testing in Android. Methods Unit Testing Integration Testing System Testing Regression Testing Compatibility Testing Black Box (Functional) White Box.
JUnit. Introduction JUnit is an open source Java testing framework used to write and run repeatable tests JUnit is integrated with several IDEs, including.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Debugging COMP T1.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Testing Spring Applications Unit Testing.
S Ramakrishnan1 Systems V & V, Quality and Standards Dr Sita Ramakrishnan School CSSE Monash University.
1 Unit Testing with JUnit CS 3331 JUnit website at Kent Beck and Eric Gamma. Test Infected: Programmers Love Writing Tests, Java Report,
Unit Testing. F-22 Raptor Fighter Manufactured by Lockheed Martin & Boeing How many parts does the F-22 have?
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
Unit Testing with FlexUnit
Justin Bare and Deric Pang with material from Erin Peach, Nick Carney, Vinod Rathnam, Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section.
Northwest Arkansas.Net User Group Jay Smith Tyson Foods, Inc. Unit Testing nUnit, nUnitAsp, nUnitForms.
Tools for Automated Testing Presented by: Žygimantas Mockus.
CFUNITED – The premier ColdFusion conference Load and Functional Testing Flex 2 and ColdFusion Matthew Stevanus Universal Mind.
Automated Testing with PHPUnit. How do you know your code works?
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Unit Testing.
Software Construction Lab 10 Unit Testing with JUnit
Test-driven development
TESTING TEST DRIVEN DEVELOPMENT
Software Engineering (CSI 321)
Introduction to JUnit CS 4501 / 6501 Software Testing
More JUnit CS 4501 / 6501 Software Testing
Test Driven Development 1 November Agenda  What is TDD ?  Steps to start  Refactoring  TDD terminology  Benefits  JUnit  Mocktio  Continuous.
Computer Science 209 Testing With JUnit.
History, Characteristics and Frameworks
Test-driven development (TDD)
Introduction to JUnit CS 4501 / 6501 Software Testing
Advanced Programming Behnam Hatami Fall 2017.
Introduction to JUnit IT323 – Software Engineering II
Test Driven Development
CS 240 – Advanced Programming Concepts
Principles of Object Oriented Programming
Presentation transcript:

Unit and Functional Testing Your Flex Applications Mike Nimer Dir. Of Engineering nomee.com

2www.cfunited.com Isolate each part of the program and show that the individual parts are correct. Provide a strict, written contract that the piece of code must satisfy. Find problems early in the development cycle. Unit testing allows the programmer to re-factor code at a later date, and make sure the module still works correctly --wikipedia The goal(s) of testing

3www.cfunited.com Types of Testing Manual Humans create test scripts. Step by Step instructions (word doc). Humans execute those tests. Low cost to begin. High cost over the life of a project Testing generally happens less often Automated Humans create test methods. Machines execute those tests. Higher cost to develop. Much lower cost over the life of a project Testing can happen continually On every check-in

4www.cfunited.com Automated Testing Testing as part of Development As developers create code, they create tests Test Driven Development – tests first, code 2nd Tests are continually executed by developer to ensure new code does not break existing features Automated build/test environments Part of “Continuous Integration” Code checked out and built automatically Code continually tested with your tests and reports generated Automated QA ensuring a last minute check in does not break a release

5www.cfunited.com Types of Automated Testing Unit Tests the smallest unit of code that is possible Usually tests a single method or function Multiple tests for every path through a method Usually created by Developer Integration / functional Tests a combination of units Can be used to test UI Components Confirms that individual pieces of code work together Created by Developer or QA

6www.cfunited.com Tools for Unit Testing Unit Testing (before) FlexUnit - The original Flex/ActionScript 3.0 unit testing framework. Fluint –Written for better asynchronous support and support for testing UI components. (today) FlexUnit 4 – A merge of FlexUnit 3 and Fluint. Providing better asyncronous testing support, support for UIComponent testing and IDE integration.

7www.cfunited.com Tools for Automated Testing These products all use the Flex Automation API, to monitor, manipulate, and control the Flex application. FlexMonkey TestComplete Selenium (with SeleniumFlex project) Mercury QuickTest Pro 9.1 (QTP) Borland SilkTest IBM Rational Functional Tester

8www.cfunited.com Testing Terminology Test Method - A test method is the smallest unit of the testing process. A test method executes code and checks the outcome. At the end of the test method the developer generally makes an “assertion”, stating the expected outcome of this executed code. Test Case - A test case is a collection of test methods that share a common test environment, also referred to as a test fixture. Test Suite - A test suite is a collection of test cases. Test Runner - A test runner is an application that executes the test methods in your suites and cases.

9www.cfunited.com Understanding Assertions assertEquals()—Accepts two parameters and is a valid assertion if the two values are equal (==). assertStrictlyEquals()—Accepts two parameters and is a valid assertion if the two values are strictly equal (===). assertTrue()—Accepts a single parameter and is a valid assertion if the value is true. assertFalse()—Accepts a single parameter and is a valid assertion if the value is false. assertNull()—Accepts a single parameter and is a valid assertion if the value is null. assertNotNull()—Accepts a single parameter and is a valid assertion if the value is not null. fail()— Marks the test failed.

10www.cfunited.com Whats new in FlexUnit 4 Support for all Junit 4 features Support for UI testing Metadata driven Exception handling New attribute of [Test] Metadata allows you to define expected exceptions (instead of using try/catch) [Test(expects=“TypeError”)] Async test support Support for multiple Runners Hamcrest support Uses the Hamecrest AS3 project for a richer set of Asserts. Theories and Assumptions IDE Support Beta 1 now available.

11www.cfunited.com Understanding Metadata FlexUnit 4 can be driven off of specific flexmetadata (similar to java annotations). This allows you to define tests as you see fit, with your own naming conventions or in existing code. Before metadata you had to name your test methods a certain way, and your tests had to extend specific classes. [Test] [Suite] [Before] [After] [BeforeClass] [AfterClass] [Ignore] [DataPoints] [Theory] [RunWith]

12www.cfunited.com Creating A Basic Unit Test package simpleTest.tests{ import org.flexunit.Assert; public class SimpleTestCase{ [Test] public function testMath():void { var x:int = 5 + 3; Assert.assertEquals( 8, x ) }

13www.cfunited.com Creating A Basic Test Suite package simpleTest { import flexunit.framework.TestSuite; import simpleTest.tests.SimpleTestCase; [Suite] [RunWith("org.flexunit.runners.Suite")] public class SimpleTestSuite { // define a var for each test case. public var simpleTestCase:SimpleTestCase; }

14www.cfunited.com Creating A Test Runner <mx:Application xmlns:mx=" creationComplete="runMe()" xmlns:flexUnitUIRunner=" > <![CDATA[ import simpleTest.SimpleTestSuite; import org.flexunit.listeners.UIListener; import org.flexunit.runner.FlexUnitCore; private var core:FlexUnitCore; public function runMe():void { core = new FlexUnitCore(); //Listener for the UI, optional core.addListener( new UIListener( uiListener )); core.run( SimpleTestSuite ); } ]]> <flexUnitUIRunner:TestRunnerBase id="uiListener" width="100%" height="100%" />

15www.cfunited.com Asynchronous Testing Asynchronous Tests examples Server calls Timers AIR Sqlite AIR File Access

16www.cfunited.com Creating an Asynchronous Unit Test – Setup/Teardown [Before(async)] public function setUp():void{ timer = new Timer( 500, 3 ); } [After(async)] public function tearDown():void { if ( timer ) { timer.stop(); } timer = null; }

17www.cfunited.com Creating an Asynchronous Test – Test Method [Test(async)] public function testInTimePass() : void { var obj:Object= {expected:3} timer.delay = 100; timer.addEventListener(TimerEvent.TIMER_COMPLETE, Async.asyncHandler( this, completehandler, 500, obj, null), false, 0, true ); timer.start(); } protected function completehandler( event:Event, data_:Object):void{ if( event.type == "timerComplete” && ){ Assert.assertEquals(Timer(event.target).currentCount, data_.expected ); }else{ Assert.fail("wrong event type"); }

18www.cfunited.com Integration Testing UIComponents A common goal when developing Flex applications is to test UIComponents in a repeatable way UIComponents are internally asynchronous

19www.cfunited.com Integration Testing (FlexUnit) FlexUnit Sequences Sometimes a test of a UIComponent can require many steps to setup. For example, you may need to create a Login Form, populate it and then click a button before you can decide if everything worked Sequences are a shorthand to simplify that work into a readable set of steps

20www.cfunited.com Testing UIComponents – setup public var form:LoginForm; [Before(async,ui)] public function setUp():void { form = new LoginForm(); Async.proceedOnEvent( this, form, FlexEvent.CREATION_COMPLETE, 200 ); UIImpersonator.addChild( form ); } [After(async,ui)] public function tearDown():void { UIImpersonator.removeChild( form ); form = null; }

21www.cfunited.com Testing UIComponents – test method [Test(async,ui)] public function testLogin():void { var passThroughData:Object = new Object(); passThroughData.username = 'myuser1'; passThroughData.password = 'somepsswd'; var sequence:SequenceRunner = new SequenceRunner( this ); sequence.addStep( new SequenceSetter( form.usernameTI, {text:passThroughData.username} ) ); sequence.addStep( new SequenceWaiter( form.usernameTI, FlexEvent.VALUE_COMMIT, 100 ) ); sequence.addStep( new SequenceSetter( form.passwordTI, {text:passThroughData.password} ) ); sequence.addStep( new SequenceWaiter( form.passwordTI, FlexEvent.VALUE_COMMIT, 100 ) ); sequence.addStep( new SequenceEventDispatcher( form.loginBtn, new MouseEvent( 'click', true, false ) ) ); sequence.addStep( new SequenceWaiter( form, 'loginRequested', 100 ) ); sequence.addAssertHandler( handleLoginEvent, passThroughData ); sequence.run(); } protected function handleLoginEvent( event:TextEvent, passThroughData:Object ):void { Assert.assertEquals( passThroughData.password, event.text ); }

22www.cfunited.com Testing UIComponents – test method var sequence:SequenceRunner = new SequenceRunner( this ); sequence.addStep( new SequenceSetter( form.usernameTI, {text:passThroughData.username} ) ); sequence.addStep( new SequenceWaiter( form.usernameTI, FlexEvent.VALUE_COMMIT, 100 ) ); sequence.addStep( new SequenceSetter( form.passwordTI, {text:passThroughData.password} ) ); sequence.addStep( new SequenceWaiter( form.passwordTI, FlexEvent.VALUE_COMMIT, 100 ) ); 1.Create a new Sequence 2.Set a property on a UIComponent 3.Wait for the “valueCommit” event to fire, so you know the property was set correctly.

23www.cfunited.com Testing UIComponents – test method sequence.addStep( new SequenceEventDispatcher( form.loginBtn, new MouseEvent( 'click', true, false ) ) ); sequence.addStep( new SequenceWaiter( form, 'loginRequested', 100 ) ); sequence.addAssertHandler( handleLoginEvent, passThroughData ); sequence.run(); 1.Add a new step that simulates a user clicking on the “login” button. 2.Wait for the “loginRequested” event. 3.Add an “assertHandler” to check the login when it is completed. 4.Run the test.

24www.cfunited.com Testing UIComponents – test method //sequence.addAssertHandler( handleLoginEvent, passThroughData ); protected function handleLoginEvent( event:TextEvent, passThroughData:Object ):void { Assert.assertEquals( passThroughData.password, event.text ); } 1.Use the assertHandler method to test the results of the login action (server call) 2.If the right data exists, success.

25www.cfunited.com Integration Testing (FlexMonkey) Recording Scripts Replaying Scripts

26www.cfunited.com Tips All Software projects should be thoroughly tested!! Automated testing saves you money by preventing bugs form returning again and again. A getting started rule of thumb for writing a new test case Write one test that passes the “usual” case Write one test that passes by testing the extremes Write one test that is supposed to fail Continue building your test cases, by writing a test case for every bug that is submitted – before you close the bug as fixed. Tests cases should “clean up” after themselves Any developer should be able to run the tests without custom setup – if possible.

27www.cfunited.com Questions ?

28www.cfunited.com FlexUnit 4 Flex Monkey More on Continuous Integration