I just start to study Unit Testing (using FlexUnit). I still have not sure how to use them.
I created a new flex project, and created a class named Car
. Then, I created a TestCase class, for Car class.
This is the default template that FlexBuilder gave to me, and I put some traces.
package flexUnitTests
{
import flexunit.framework.Assert;
public class CarTest
{
[Before]
public function setUp():void
{
trace('before test function');
}
[After]
public function tearDown():void
{
trace('after test function');
}
[BeforeClass]
public static function setUpBeforeClass():void
{
trace('before test class');
}
[AfterClass]
public static function tearDownAfterClass():void
{
trace('after test class');
}
[Test]
public function testCar():void
{
trace('the test function');
var c:Car = new Car("gol");
Assert.assertTrue("Is car name valid:", c.name != "gol");
}
}
}
I can't understand why I have so many methods to run before or after a test function. Why not just use them within a simple funcion, like:
[Test]
public function testCar():void
{
trace('before test class');
trace('before test function');
trace('the test function');
var c:Car = new Car("gol");
Assert.assertTrue("Is car name valid:", c.name != "gol");
trace('after test function');
trace('after test class');
}
A second question I want to add is, these tests test each class individualy, (like shown when instancianting Car
class) or a I can test my whole application once by instanciating the main class? The problem is how to simulate the whole userflow of the application (user clicks here, send a request to server there, etc, etc). I should write a whole flow one by one in a test method? :O