What is a Test?

A Test, "Unit Test," or TestMethod is the basic element of the entire FlexUnit framework. Simply put, it is a method meant to verify the expected behavior of a very narrow use case of a class, a global method, or any bit of isolatable code, providing a simple pass/fail result. In its most basic form, it is made up of two parts:

  • The code you are testing and in the use case you are testing.
  • The criteria for a pass.

Take, for example, the Math.pow() method. Although it is probably safe to assume that this method works, let's suppose we wanted to test it under a particular use case, say, getting the result of five squared (ie: Math.pow(5,2). This makes up the first part, mentioned above. The code you are testing is Math.pow(); the use case is providing the parameters 5,2. To test this, we would write a method (a test) that multiplies five times five and then verifies that the result is equal to the result of the Math.pow() call. This makes up the second part. The criteria for pass is that Math.pow(5,2) equals 5 x 5. If it does, the test passes. If it doesn't, the test fails. That's all there is to it.

To see the actual syntax of a test and a concrete code example, see Writing a Basic Test.

NOTE: It is worth noting that a test is assumed to pass unless it explicitly fails, either by a) not meeting explicitly-specified pass criteria or by b) throwing an error while running the test. In other words, a test is innocent until proven guilty.

What is a Test Case?

A TestCase is a class that contains a) a set of related tests and b) any additional code that should apply across a set of tests. Examples of the latter include, but are not limited to:

  • Global variables that will be used in most or all tests (ex: components you're testing against)
  • Additional FlexUnit 4.x functionality that applies across multiple tests (Note: These include advanced features beyond the purview of this section), like:
    :-Before/After
    :-BeforeClass/AfterClass
    :-Rules
  • Specifying a custom runner to use for the tests

In many cases, a Test Case serves the sole purpose of grouping related tests.

  • No labels