Test Profile App Unit Test Code Coverage
NoteBefore you run the Unit Test and Code Coverage, make sure:
- You have an Emulator or a connected target device running.
- If you want to try out the tool and do not have an applicable project to test, create a project with the Project Wizard using a template or a sample. For more information on creating a project, check Native Application Development.
To create a Unit Test project
You can create a test project for Tizen Native Project through the Tizen Native Unit Test Project Wizard. The wizard provides the test project for each Tizen Native project type, such as UI application, service application, shared library, and static library.
To create a test project, follow these steps:
-
In the Visual Studio Solution Explorer, right-click on the solution name, select Add > New Project > Tizen Native Project, and click on Next button. As illustrated in the following figure:
-
In the Configure your new project window, select a name for the Unit Test project > click on create button > select gtest template > press OK as illustrated in the following figure:
To configure the Unit Test project for Native App
-
Right-click on the Unit Test project > select Add Tizen Project Dependency > Select the Native App > press OK as illustrated in the following figure:
-
Again right-click on the Unit Test project > select Set as Startup Project
-
To use the test project, follow these steps:
-
<TEST_PROJECT_HOME>/<TEST_PROJECT_NAME>/src/<TEST_PROJECT_NAME>_test.cpp
file. -
Add a
TEST_F()
test case.Each
TEST_F()
test case is independent. If theTEST_F()
test case is associated with a fixture class name, the test case runs based on that fixture class. -
Add assertions:
The Unit Test tool supports basic assertions, binary comparison, and string comparison in the gtest. For more information, check Google Test Advanced Guide.
-
Call a method of the main Native project in the test case:
The header of the Native App should be included in the Unit Test project cpp file (in this example: the
ADD()
method is described intizennative3.c
, so the headertizennative3.h
is included). As illustrated in the following figure:In case if the Native project is written in C code, use extern to include the header (To know more details about extern, visit extern (C++)).
The method declaration should be mentioned in the header file.
-
Enclose the main() function of the Native project with
TEST_BUILD
:#ifndef TEST_BUILD //main method #endif
-
To run the Unit Test project on devices
To launch the Unit Test project, click the Run(ctrl + f5) icon in the toolbar.
After the test cases are executed, the results are displayed on the Native Unit Test Result in Explorer View and the Code Coverage information is displayed in the default browser in the form of HTML.
-
Explorer view
-
Upon double click on the failed test case, the cursor will navigate to the line the test case failed. As illustrated in the following figure:
-
-
HTML Code Coverage report
-
The index.html page is opened in the browser to view the Code Coverage Report, as illustrated in the following figure:
-
Click on any of the projects to get the coverage at the file level, as illustrated in the following figure:
-