Podcast
Questions and Answers
What is the primary goal of unit testing?
What is the primary goal of unit testing?
- To prepare the code for deployment
- To test the code in small, individual units (correct)
- To analyze the performance of the software application
- To validate user requirements
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?
- Gathering return values to compare with expected output
- Deploying the code to production (correct)
- Feeding the function specific values
- Using assertions to handle test failures
What does test coverage measure?
What does test coverage measure?
- The depth of testing in terms of feature completeness
- The performance impact of the tests on the system
- The extent to which the source code is tested by test cases (correct)
- The number of test cases executed during testing
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?
What is the role of assertions in unit testing?
What is the role of assertions in unit testing?
What is the purpose of the Assert::AreEqual method?
What is the purpose of the Assert::AreEqual method?
Which of the following test methods correctly validates a square operation?
Which of the following test methods correctly validates a square operation?
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?
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)?
Which of the following correctly describes the Fail method?
Which of the following correctly describes the Fail method?
Which of the following statements about the MathIntegrationTest class is true?
Which of the following statements about the MathIntegrationTest class is true?
In which scenario would the AreNotEqual method be used?
In which scenario would the AreNotEqual method be used?
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)?
Flashcards
Unit Testing
Unit Testing
Testing small parts (functions) of code with specific input values to check if their output matches expectations.
Test Framework
Test Framework
Tools that organize the process of setting up tests, executing functions, comparing results, and handling test failures.
Test Coverage
Test Coverage
A measure of how much of the code was executed during testing.
Testing Steps (Unit)
Testing Steps (Unit)
Signup and view all the flashcards
Test Coverage Metric
Test Coverage Metric
Signup and view all the flashcards
Assert::AreEqual()
Assert::AreEqual()
Signup and view all the flashcards
Assert::AreNotEqual()
Assert::AreNotEqual()
Signup and view all the flashcards
Assert::IsTrue()
Assert::IsTrue()
Signup and view all the flashcards
Assert::IsFalse()
Assert::IsFalse()
Signup and view all the flashcards
Assert::Fail()
Assert::Fail()
Signup and view all the flashcards
TEST_METHOD
TEST_METHOD
Signup and view all the flashcards
TEST_CLASS
TEST_CLASS
Signup and view all the flashcards
square()
square()
Signup and view all the flashcards
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.