1 / 3
Caption Text
2 / 3
Caption Two
3 / 3
Caption Three margin testing

Wednesday, June 10, 2009

Integrating unit testing - Flex best practices

Flex best practices – Part 2: Development practices | Adobe Developer Connection

Unit testing can ensure the quality of your codebase. Writing test cases can lead to more reliable and better code. Testing your code will help find errors and save debugging time. Here are a few best practices that can be applied when implementing unit testing.

checkmark Test behavior instead of testing methods

Writing code to test private methods is not always needed. This should be evaluated on a case by case basis. Write code to test against an object's public API. Typically private methods are used internally by a class to support its public API.

checkmark Apply the "too simple to break" rule

Don't over test the codebase. If the method is a very simple one line method, like a getter method, don't worry about writing a test case for it.

checkmark Use standard OOP best practices in test cases

Follow the same OO methodology you use to write the rest of your application. Refactor test cases to move common functionality into base classes as appropriate.

checkmark Use clear and concise test method names

Follow the same method naming conventions used elsewhere in the application's codebase. Avoid generic names for test case methods. This helps other developers easily understand the relationship, responsibility, and purpose of the method.

checkmark Write simple test case methods

Keep test cases simple and limit the decisions that are made within them.

checkmark Use static values in the assertion method calls when possible

This reduces the chances for error in your test cases and improves the maintainability and understandability of the test code.

checkmark Document the test code

Add comments that explain what is being tested and why. Also, outline any special circumstances regarding the test.

checkmark Create independent unit tests

Each unit test should execute a single behavior for each method.

checkmark Limit assertions to one per test case

Multiple assertions in a single test case can lead to performance issues. In addition, if one assertion fails the other assertions will not be executed until the first assertion passes.

No comments:

Post a Comment

Featured Post

Windows和Ubuntu双系统完全独立的安装方法

http://www.ubuntuhome.com/windows-and-ubuntu-install.html  | Ubuntu Home Posted by Snow on 2012/06/25 安装Windows和Ubuntu双系统时,很多人喜欢先安装windows,然...