Unit Testing of native C ++ in Windows Mobile and Windows Mobile

Source: Internet
Author: User

Unit test has become an integral part of the development process and is also the basis of refactoring. cppunitlite can be used for unit testing when developing native C ++ on Windows Mobile and Windows Mobile.

When developing C ++ on other platforms, I have been using cppunit for unit testing. However, cppunit does not support the wince platform. Therefore, cppunitlite is selected for unit testing under wince. Cppunitlite is a unit test framework for C ++ re-developed by Michael feathers, creator of cppunit. Its purpose is to develop separate test cases more easily (only a test macro is required to automatically register the test, without the need to use functions at the same time, header file and register three different files .) Cppunitlite removes some new features of C ++, such as rtti, exceptions, and templates, so cppunitlite is easier to transplant. cppunitlite fully supports wince and Windows Mobile.


Environment Construction

The following describes how cppunitlite is built in Windows Mobile and Windows Mobile.

Download cppunitlitefrom http://www.objectmentor.com/resources/bin/cppunitlite.zip.

Create a smart device project

 

Select the corresponding platform. Because this is the native library, the output is related to the platform. You need to select the corresponding platform for use.

 

Select static library and disable precompiled header.

 

Copy all the files in the downloaded file/OM/cppunitlite/to the cppunitlite project directory, and add all. h and. cpp under cppunitlite to the project.

 

The static library cppunitlite. Lib is generated after compilation.

 

Use cppunitlite

Create a folder named cppunitlite under the Project for unit testing, and copy the required header file to this folder.


Add the dependent library cppunitlite. lib to linker.

 

# Include " Cppunitlite \ testharness. h "

# Include<String>

Int_ Tmain (IntArgc, _ tchar*Argv [])
{
Testresult TR;
Testregistry: runalltests (TR );

Return 0;
}

Simplestring stringfrom (ConstSTD ::String&Value)
{
ReturnSimplestring (value. c_str ());
}

ClassClassa
{
Public:
IntMethod1 ()
{
Return 5;
}

DoubleMethod2 ()
{
Return 1.88587;
}

STD ::StringMethod3 ()
{
Return "String1";
}

BoolMethod4 ()
{
Return True;
}

};

Test (stack, test_simple)
{
Classa;

Longs_equal (5, A. Method1 ());
Doubles_equal (1.9, A. method2 (),0.1);
Check_equal ("String", A. method3 ());
Check (!A. method4 ());
}

 

Test is used to define the test class. The first parameter is the test name. Generally, the class name is used, and the second parameter is the name of the test group. Longs_equal is used for integer comparison, doubles_equal is used for floating point comparison, and the third parameter is precision. Check_equal is used for string comparison. Because cppunitlite does not rely on STL, The stringfrom function is required to convert STD: string to the string class of cppunitlite. Check is a logical comparison. This macro can be used for any comparison. For example, if a class overload = (equal sign operator), check can be used for comparison.

 

References 

CPP unit Lite

Windows Mobile native Unit Testing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.