Difference between revisions of "Unit Test Framework"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
Line 1: Line 1:
In the {{enterprisebrand}} platform, the Unit Test Framework makes it possible to define tests in your classes, and then run them on one class at a time, or on all of your classes at once.
In the {{enterprisebrand}}, the Unit Test Framework makes it possible to define tests in your classes, and then run them on one class at a time, or on all of your classes at once.


== About Unit Testing ==
== About Unit Testing ==
Line 25: Line 25:
# Select a class
# Select a class
# Click '''Run Tests'''
# Click '''Run Tests'''
#: All tests defined in the class are run, and the '''Test Results''' page appears.
#: All tests defined in the class are run. The results page appears.


===Test Results===
===Test Results===
Line 36: Line 36:
#: '''Designer > Logic > Classes'''
#: '''Designer > Logic > Classes'''
# Click '''Run All Tests'''
# Click '''Run All Tests'''
#: Tests are run for all classes, and the '''All Test Results''' page appears.
#: Tests are run for all classes. The results page appears.


===All Test Results===
===All Test Results===
Line 44: Line 44:


{{:Code Coverage}}
{{:Code Coverage}}
<noinclude>


[[Category:Tools and APIs]]
[[Category:Tools and APIs]]
</noinclude>

Revision as of 02:03, 30 July 2011

In the AgileApps Cloud platform, the Unit Test Framework makes it possible to define tests in your classes, and then run them on one class at a time, or on all of your classes at once.

About Unit Testing

Unit Testing is the key that unlocks the door to programming nirvana. As your suite of unit tests grow, bugs that would have been exceptionally deep suddenly become extraordinarily shallow--because some test, somewhere, surfaces the "violation of expectations" that occurs when a method deep in the belly of the code returns an unexpected value. Without a comprehensive test suite, you find yourself laboriously tracing your way down a chain of calls to find it. But with a comprehensive test suite, debugging frenzies are a thing of the past; Because one of your unit tests inevitably takes you right to the source of the problem, where there are only a few lines of code to debug.

In addition, as Martin Fowler points out so well, a comprehensive suite of unit tests makes it possible to refactor with impunity. If that new feature you want to add requires drastic reorganization of the code, no worries. Your comprehensive test suite makes sure that after refactoring, everything works in exactly the same way it did before.

Note:
Fowler's particular genius lay in pointing out that you what seems like a very large refactoring can be broken down into a number of much smaller steps. So you do a small amount of refactoring, and then run the test suite to make sure everything is still working. If everything succeeds, you do a bit more of the refactoring. If it isn't working, you fix things, or even back out your changes and start over. At every stage of the process, everything works exactly the way it did before. By the end of the process, it's possible to have made very large changes, and at the same time know that you haven't broken anything.

Of course, you only get a comprehensive test suite if you write your tests as you go along, side by side with your code. In fact, it's a generally considered a good idea to write tests before you write your code. That way, (a) You're guaranteed to have them and (b) You know with certainty when your code is working the way you expect it to.

In a way, unit tests also provide highly detailed, totally accurate documentation of your APIs. In some shops, in fact, you're not even allowed to commit code to the shared repository unless it is accompanied by the tests which describe the behavior, and at the same guarantee compliance with the description.

Finally, to make it all work, you need an automated test harness that will run your tests and make it possible to quickly zero in on any that failed. That is the goal of the Unit Test Framework.

Defining Unit Tests

Defining Unit Tests

Running Unit Tests on a Class

To run tests for a class

  1. Go to the list of Classes
    Designer > Logic > Classes
  2. Select a class
  3. Click Run Tests
    All tests defined in the class are run. The results page appears.

Test Results

This page shows the results of running the tests defined in a class.

Summary

  • Tested Class - The class that was tested.
  • Tests Run - The total number of test methods that were executed.
  • Test Failures - Tests that failed, either because an assertion failed or because an exception occurred.
  • Tests Succeeded - A count of the number of assertions that succeeded. If a single test method makes 2 assertions, and each succeeds, it counts as 2 successful tests.
  • Total Time (ms) - The total amount of time that was taken to execute the tests, in milliseconds.

Notepad.png

Note: Tests that run to completion without making any assertions are not counted.

Failed Methods

This section shows the tests that failed, either because an exception occurred or because an assertion statement turned out to be false. The error message is displayed in either case. If there was an exception, a stack trace is shown, as well.


Running Unit Tests for All Classes

To run tests for all classes

  1. Go to the list of Classes
    Designer > Logic > Classes
  2. Click Run All Tests
    Tests are run for all classes. The results page appears.

All Test Results

This page shows the results of running the tests defined in all classes.

Column Headings

  • Tested Class - The class that was tested.
  • Tests Run - The total number of test methods that were executed.
  • Test Failures - Tests that failed, either because an assertion failed or because an exception occurred.
  • Tests Succeeded - A count of the number of assertions that succeeded. If a single test method makes 2 assertions, and each succeeds, it counts as 2 successful tests.
  • Total Time (ms) - The total amount of time that was taken to execute the tests, in milliseconds.

Notepad.png

Note: Tests that run to completion without making any assertions are not counted.


Code Coverage

Code Coverage