Vault7: CIA Hacking Tools Revealed
Navigation: » Latest version
Owner: User #1179751
7. The Art of Unit Tests
EDG Unit Testing
Unit testing as you may already know is intended to test functionality for each function. Unit tests should examine the good, bad, and ugly. The good being the expected arguments to the function, bad being invalid arguments and ugly being all the applicable edge cases. In EDGEngineering Development Branch we have found Google Test to provide a pretty helpful unit testing framework. We have also added on to the Google Unit Test Framework to help improve our test coverage and for DARTTest-Software (commercial) integration. The repository for Google Test can be invidually cloned or added via the EDGEngineering Development Branch Project Wizard (easier).
Alright, so let's get into some of the syntax Google Test uses (the internet has more comprehensive documentation and examples). A simple test contains a TestCaseName and a TestName. These names allow you to group and identify your tests. At the beginning of the test function you can use the CrtCheckMemory object to test against memory leaks in the test. Next, execute your tests and validate your return values. Google Test has two types of failure recognitions. ASSERT_* means that if the evaluation fails, the unit tests stop. EXPECT_* identifies the failure but does not prevent further execution of unit tests. Below are some examples of unit tests that show each of these capabilities as well as some tips on how to filter your test executable.
Unit Test Examples
Example 1: Verify function return and functionality
Example 2: Expect vs Assert and some operands
Note: The third test never gets tested because the ASSERT failed.
Example 3: Using Google Test Plugin
Example 4: CrtCheckMemory
Example 5: List All Tests
Example 6: Run groups of Tests
Unit Test Exercise
Step 1: Clone New Developer Exercise 5
Step 2: Open up the tests in Visual Studio and compile
Step 3: If you're using the Google Test Add-On, open the google test view. Otherwise, you can run the executable in a console window.
Step 4: Analyze the results of the test, note the issues and the line numbers.
Step 5: Analyze the unit tests and identify the issues in the function
Step 6: Fix the functions so they pass all unit tests
Step 7: Create a new branch with your name, push the branch, set User #1179751 or User #71473 as the approvers.