Podcast
Questions and Answers
What is the primary goal of unit testing?
What is the primary goal of unit testing?
Which of the following steps is NOT part of the unit testing process?
Which of the following steps is NOT part of the unit testing process?
What does test coverage measure?
What does test coverage measure?
Which command is used to compile code with counting flags for test coverage?
Which command is used to compile code with counting flags for test coverage?
Signup and view all the answers
What is the role of assertions in unit testing?
What is the role of assertions in unit testing?
Signup and view all the answers
What is the purpose of the Assert::AreEqual method?
What is the purpose of the Assert::AreEqual method?
Signup and view all the answers
Which of the following test methods correctly validates a square operation?
Which of the following test methods correctly validates a square operation?
Signup and view all the answers
What would be the outcome of calling the IsTrue method with a false boolean?
What would be the outcome of calling the IsTrue method with a false boolean?
Signup and view all the answers
What is the expected result of the CubeTest method when evaluating cube(3.0)?
What is the expected result of the CubeTest method when evaluating cube(3.0)?
Signup and view all the answers
Which of the following correctly describes the Fail method?
Which of the following correctly describes the Fail method?
Signup and view all the answers
Which of the following statements about the MathIntegrationTest class is true?
Which of the following statements about the MathIntegrationTest class is true?
Signup and view all the answers
In which scenario would the AreNotEqual method be used?
In which scenario would the AreNotEqual method be used?
Signup and view all the answers
What would the output be if Assert::AreEqual(91.0, d + d1) is called with d = square(8.0) and d1 = cube(3.0)?
What would the output be if Assert::AreEqual(91.0, d + d1) is called with d = square(8.0) and d1 = cube(3.0)?
Signup and view all the answers
Study Notes
Software Testing - Unit Testing
- Unit testing is the process of testing small units of code.
- Typically, these units correspond to functions.
- Steps to test units:
- Provide specific input values to the function.
- Collect the return value from the function.
- Compare the return value to the expected output.
- If the actual output matches the expected output, the test passes.
Software Testing - Test Frameworks
- Unit test frameworks aid in setting up tests.
- Frameworks allow for calling functions and storing results.
- The result is compared to the expected outcome.
- Assertions are used to throw exceptions if tests fail.
- The framework also involves a teardown step.
- Common steps within unit test frameworks include
- Test Setup
- Execution (calling the function under test)
- Checking the result (comparing to expected outcome)
- Test Tear-Down (cleanup)
Software Testing - Test Coverage
- Test coverage assesses how much of the source code is covered by a set of test cases.
- It's a metric for evaluating testing efficiency.
- Measures the lines of code executed during tests.
- Measures how many times each line of code is executed.
- Steps to perform test coverage analysis:
- Compile the code with special flags for coverage.
- Execute the target program.
- Generate a report using the gcov tool.
- Examine the generated *.gcov file to see line-by-line coverage and execution count data.
Software Testing - Test Math Functions
- Example includes for testing math functions in C code(using Header file):
-
mathfuncs.h
(header file): Contains function declarations (square
andcube
). -
mathfuncs.c
: Contains function definitions forsquare
andcube
. -
main
: Example usage of thesquare
method.
-
Creating a Test Project
- Several templates are available for different programming languages (C++, etc.).
- Available templates include
Native Unit Test Project
,Console App
, andLibrary
projects.
Writing Test Code
- Includes header files for unit testing (such as
CppUnitTest.h
). - Uses a test framework (e.g., Microsoft Visual Studio's
CppUnitTestFramework
). - Examples of test methods:
-
SquareTest
: Tests thesquare
function. -
CubeTest
: Tests thecube
function. -
AdditionTest
: Tests addition of function outputs (e.g.,square(8)
+cube(3)
).
-
Access C Include File
- The C include file (
mathfuncs.h
) is included into the test framework.
Assertions
- Methods for checking conditions within the tests:
-
AreEqual(v1, v2)
compares values and throws exceptions if they are not equal. -
AreNotEqual(v1, v2)
compares for inequality, throwing exceptions on equality. -
IsTrue(b1)
checks forb1
beingtrue
. -
IsFalse(b1)
checks forb1
beingfalse
. -
Fail()
forces a test failure.
-
Setup Library Path
- This involves setting up the correct paths within Visual Studio for linking required libraries.
- The process involves configuring the library paths to allow linking with needed libraries.
Setup Include Path
- Setting the directory where header files reside
- This ensures the compiler can find the required project headers.
Running Tests in Visual Studio
-
Test Explorer
window allows controlling and running tests. - Results are displayed in the explorer window, indicating durations, success or failure, etc.
Test Results
- Test explorer displays results such as duration, success, failure conditions.
- Reports can be filtered using the menu.
Setup and Teardown Before/After Tests
-
TEST_MODULE_INITIALIZE
sets up resources for the module. -
TEST_MODULE_CLEANUP
releases resources of the module. -
TEST_CLASS_INITIALIZE
andTEST_CLASS_CLEANUP
are similar but for individual test classes.
Test from Command Line
- Executable tool
vstest
from the command line is used to run tests. - The tool reports test pass/fail conditions and durations.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
This quiz focuses on the fundamentals of unit testing, including its processes, frameworks, and coverage assessments. You will learn about the steps involved in conducting unit tests, utilizing test frameworks effectively, and understanding test coverage principles. Whether you're new to software testing or looking to refresh your knowledge, this quiz is for you.