Before Reading this documentation. Its been a simple effort by me to share the information whatever i have with all of the world through internet. So whatever written is all what i had understood from the FlexUnit Framework it may have some mistakes so sorry for those. But Please do inform me if you find something wrong with it ,so that this can be of great help to everybody who navigates to this page.
This is the First big document which i have made and published so Please do comment if you think you can help me or give me a some suggestions.
Thanks in Advance.
Some Definitions
Code coverage : Code coverage is a measure used in software testing. It describes the degree to which the source code of a program has been tested. It is a form of testing that inspects the code directly and is therefore a form of white box testing (Testing done only on internal specification).
Test harness or automated test framework : It is a collection of software and test data configured to test a program unit by running it under varying conditions and monitoring its behavior and outputs.
The typical objectives of a test harness are to:
ØAutomate the testing process.
ØExecute test suites of test cases.
ØGenerate associated test reports.
A test harness typically provides the following benefits:
ØIncreased productivity due to automation of the testing process.
ØIncreased quality of software components and application.
Regression : Regressions occur whenever software functionality that was previously working correctly stops working as intended. Typically regressions occur as an unintended consequence of program changes.
Test Case : A test case in software engineering is a set of conditions or variables under which a tester will determine whether a application meets specifications. Test cases are often referred to as test scripts, particularly when written. Written test cases are usually collected into test suites.
Test Oracle: The mechanism for determining whether a software program or system has passed or failed a test . In some settings an oracle could be a use case or Requirement. It may take many test cases to determine that a software program or system is functioning correctly.
Mock objects : mock objects are simulated objects that mimic the behavior of real objects in controlled ways. In a unit test, mock objects can simulate the behavior of complex, real (non-mock) objects and are therefore useful when a real object is impractical or impossible to incorporate into a unit test.
Feature creep : It is the proliferation of features in a product where extra features go beyond the basic function of the product and so can result in over-complication rather than simple, elegant design.
Unit testing
What is Unit and Unit testing?
Unit testing is a method of testing that verifies the individual units of source code are working properly. A unit is the smallest testable part of an application. In Flex, thismeansafunction, or more appropriately a method as Flex/ActionScriptisanobject orientedlanguage.
Unlike many other forms of software testing, unit tests are usually completed by the developer.
The developer tests code at a low level to make sure each method is performing as expected. In theory, if each function is working properly at a low level then the higher levels of integrtion testing should have fewer errors.
Why ?
To ensures that new additions or changes to a project do not introduce bugs or modify expected behavior.
To enables large teams to work in tandem without introducing bugs and confirm that small individual parts of a program, down to specific methods, all return the expected results.
When ?
Before writing a code for any functionality we should pass a unit test for every functionality.
Reasons for Unit Testing
Tests Reduce Bugs in New Features
Tests Are Good Documentation
Tests Reduce the Cost of Change
Tests Improve Design
Tests Allow Refactoring
Tests Defend Against Other Programmers to make unwanted changes
Testing Forces You to Slow Down and Think which gives clean and simple design
Tests Reduce Fear of worrying about breaking existing code as you add new features.
FlexUnit
“FlexUnit is an open source framework created by Adobe for unit testing in Flex”
The FlexUnit Framework allows you to create test cases and synchronous tests and evaluate test suites in a test harness application that provides a visual display of all the tests in that test suite.
The visual display has a very clear Representation for
Number of Tests Run, Time Taken to Run Tests, Average assertions made per Test,Number of Errors, Failures and so on
It has Filter Option for results and Search functionality
Table View representation where we can check Result, Assrtion , expected and Actual
We can Handle Events and Test Visual Components with FlexUnit
TestCase –It defines the fixture in which to run multiple tests it inherits Assert class which provides all types of assertions(Assuptions).
Assertion Types
assertEquals – Asserts that 2 values are equal.
assertFalse – Asserts that a condition is false The first argument can bethe message when the assertion fails.
assertMatch – Asserts that a string matches a regexp.
assertNoMatch – Asserts that a string doesn’t match a regexp.
assertNotNull – Asserts that an object is not null.
assertNotUndefined – Asserts that an object is not undefined.
assertNull – Asserts that an object is null.
assertStrictlyEquals – Asserts that two objects are strickly identical The first argument can be the message when the assertion failsAssert
assertTrue – Asserts that a condition is true The first argument can be the message when the assertion failsAssert
assertUndefined – Asserts that an object is undefined.
Steps in Writing the TestCases
•Write a single test
•Implement just enough code to get the test to compile
•Run the test and see it fail
•Implement just enough code to get the test to pass
•Run the test and see it pass
•Refactor for clarity
•Repeat
Unit Testing Example
Problem :We have to make functionality of checking an opening Balance for Account. If Account is of Type saving , then the Opening balance will be 1000 and if it is of type Current Account then opening balance is 5000.
Adding Tool Tips to Datagrid and Combobox Guess How Can we do it ,,, Dont Worry we have solution just check this just add the property itemRenderer=”mx.controls.Label” and Your Done
Best Luck
<?xml version=”1.0″ encoding=”utf-8″?>
<!– Adding Tooltips to Data grid and Combobox –>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”
layout=”vertical”
verticalAlign=”middle”
backgroundColor=”white”>
<mx:XML id=”dataGridDP”>
<nodes>
<node Alphabets=”A” A-ZString=”The quick brown fox jumped over the lazy dog” />
<node Alphabets=”B” A-ZString=”The quick brown fox jumped over the lazy dog” />
<node Alphabets=”C” A-ZString=”The quick brown fox jumped over the lazy dog” />
<node Alphabets=”D” A-ZString=”The quick brown fox jumped over the lazy dog” />
<node Alphabets=”E” A-ZString=”The quick brown fox jumped over the lazy dog” />
</nodes>
</mx:XML>
We all know Array and Arraycollection provides the facilities of doing sort in themselves but some times there are needs to search the Array/Arraycollection depending on the entered search term. So that is something which we need to implement. So here is the simple logic to search the item in the Array/Arraycollection
FullScreen Application in Flex,, Yup sounds very interesting…
It has been one of our project requirement , I did it quite long days ago, So I thought why not put this thing here on blog so if somebody faces any problem with it he can use this code … Why Not?
Before proceedingas you makes your new project goto your HTML wrapper i.e.
index.template.html . Now
Step 1.
In the script section add comman (,) in last property ofAC_FL_RunContent function and add the line
“allowFullScreen”, “true”
Also in <object> tag add
<param name=”allowFullScreen” value=”true” />
Property so that we can avoid upcoming Security error.
private var arrList:ArrayCollection = new ArrayCollection([{Label:'Central Beer',Path:'assets/get_video1111.flv'},{Label:'Clinton',Path:'assets/Clinton.flv'},{Label:'Banned Ad',Path:'assets/bannedAd.flv'},{Label:'Love',Path:'assets/get_video.flv'},{Label:'Darling',Path:'assets/get_video2.flv'},{Label:'Just Call US',Path:'assets/get_video3.flv'}])
We all know that to make use of browse window facility, Flex provides inbuilt class ‘FileReference’ which has method named “browse”, Which allows us to open the File Browsing window.
To restrict the Browsing window to open some limited file extensions(Such as .mp3,.mp4 file only), we make use of FileFilter class which holds the fileFilter to be applied to the browsing window
eg.
private var allFileFilter:FileFilter = new FileFilter(”All, *.mp3; *.mp4; *.flv; *.wmv; *.mpeg; *.mpg;”, “*.mp3; *.mp4; *.flv; *.wmv; *.mpeg; *.mpg; “);
private var fileRef:FileReference = new FileReference();
fileRef.browse([allFileFilter]) ;
But this File filter validation can be broken easily to Upload wrong files, For this just type *.* and press enter , Here you see all files available for upload Now select Any Invalid file and go with upload.
So in such cases we need to apply self made file extesion validation logic which should be able to verify the extension of the file to be uploaded.
So here is short and sweet sample code to workout this logic,
/**
* Standard File extensions allowed to be Uploaded
*/
private var fileTypeArray:Array = ["mp3","mp4","flv","wmv","mpeg","mpg","rtf","doc","txt"];
/**
* Selected file type,Selected from Browsing window
*/
private var fileType:String;
/**
* FileReference class object provides browsing and uploading methods
*/
private var fileRef:FileReference = new FileReference();
/**
* File Filters Applied for restriction of Files to be browsed
*/
//FileFilter takes two Arguments 1. Description to be shown in Browse window. 2. List of Extensions
private var allFileFilter:FileFilter = new FileFilter(”All, *.mp3; *.mp4; *.flv; *.wmv; *.mpeg; *.mpg;”, “*.mp3; *.mp4; *.flv; *.wmv; *.mpeg; *.mpg; “);
private var videoFilter:FileFilter = new FileFilter(”Video, *.flv; *.wmv; *.mpeg; *.mpg;”, “*.flv; *.wmv; *.mpeg; *.mpg;”);
private var audioFilter:FileFilter = new FileFilter(”Audio, *.mp3; *.mp4; *.wma;”, “*.mp3; *.mp4; *.wma;”);
private var textFilter:FileFilter = new FileFilter(”Test, *.rtf; *.doc; *.txt;”, “*.rtf; *.doc; *.txt;”);
/**
* Function for validating the correct file extension.
*/
private function validateFileType(fileName:String):Boolean
{
txtErr.text = ”;
txtFileName.text = ”;
fileName = StringUtil.trim(fileName.toLowerCase());
var fileExtensionArray:Array = fileName.split(”.”);
if(fileExtensionArray.length>1)
{
fileType= fileExtensionArray[fileExtensionArray.length-1];
for(var i:int =0;i<fileTypeArray.length;i++)
{
if(fileType==fileTypeArray[i])
{
txtErr.text = ” File Selected is of proper Extension, Thank You.”;
txtFileName.text=” Uploaded File Name is =>” + fileRef.name +
”\n Size is => “+fileRef.size+” bytes”
”\n Creation Date is => “+ fileRef.creationDate +
”\n Creator is => “+ fileRef.creator ;
return true;
}
}
}
txtErr.text = “You have not Uploaded the file within the standerd extensions provided.”;
return false;
}
/**
* Function Used to open the Browsing window
*/
private function selectFile():void
{
fileRef = new FileReference();
//browse method excepts the filefilter array as an arguement
fileRef.browse([allFileFilter,audioFilter,videoFilter,textFilter]);
fileRef.addEventListener(Event.SELECT, onSelectFile);
}
/**
* Function used to catch the Select event
*/
private function onSelectFile(event:Event):void
{
validateFileType(fileRef.name);
}
]]>
</mx:Script>
<mx:Button x=”63″ y=”86″ label=”Browse” click=”selectFile()”/>
<mx:TextArea id=”txtFileName” editable=”false” x=”161″ y=”114″ width=”360″ height=”97″/>
<mx:Text color=”#ffffff” selectable=”false” id=”txtErr” x=”161″ y=”63″ width=”397″ height=”25″/>
<mx:Label x=”143″ y=”47″ selectable=”false” text=”Enter *.* in file name of browsing window to Select wrong file.” fontWeight=”bold” fontSize=”15″/>
<mx:Label x=”161″ y=”86″ selectable=”false” text=”Retrived Local File Information => “/>
<mx:Label x=”161″ y=”256″ selectable=”false” text=”Validate wheather the selected file is valid or Not.”/>
</mx:Application>
Hi,
Changing the layout of container dynamically at runtime is one of the problem we all regularly meet with.
Suppose we are using the controlls in the HBox where all childrens are lined up horizontally and suddenly at runtime we need to place the children vertically and on some conditions we need to place all the childrens horizontally then it becomes impossible to do it with HBox
So to come up with such solution it is always easier to do it with container ‘Box’ which is actually the parent container for VBox and HBox.
With Box Container childrens are by default arranged vertically.
With the “direction” property of Box we can change its layout dynamically.
Hmm Sometimes it didnt work then try it by removing the Height and width of of that container
Following is the small Sample to workout this challege
private var prefixArray:ArrayCollection = new ArrayCollection([{Item:'Select'},{Item:'Tel'},{Item:'Mob'},{Item:'Fax'},{Item:'Freephone'},{Item:'24 Hour'},{Item:'Sales'},{Item:'Service'},{Item:'Reservations'},{Item:'Emergency'},{Item:'Textphone'}]);
private function initCombo():void
{
bx.direction=”horizontal”;
}
We all know When we use Alert.show(”Alert Popped”); If this kind of statement remains uncommented then it creats major problem into the application while deploying it on live server.
Not only this but It also becomes hectic to find and remove all the unwanted Alerts coming out there in the Application specially in large projects. So to avoid such mess I have tried to create the small utility which allows us to avoid such mess.
To Download the application use the following path
Hi, This problem is what regularly me and many Flex guys faces,
C:\WINDOWS\system32\Macromed\Flash\Flash9d.ocx
Flex Builder cannot locate the required debug version of the
Flash Player. You may need to install the debug version of Flash Player 9.0
or reinstall Flex Builder. Do you want to try to debug with the
current version?
Well my personal experience is, After installing the latest flash player version too the issue remains unresolved and i keep getting the same error. lastly I decided to reinstall flex, But amzingly after reinstallling Flex Builder I was facing the same problem and really it was very frustrating,
After spending some time Well its programmers mind afterall may not be great one, I thought before installing new version lets reinstall the First one and thats how i got the solution,
Simple Two steps Solution
1. Reinstall the flash player with flashplayer Uninstaller.
2. Install the Flash plyer.
Wait…….. I know Ur Question would be where to get uninstaller and Latest player version then click the following link