In embedded systems, unit tests typically fall under the category of software testing, specifically at the unit testing level. Unit testing focuses on testing individual units or components of software independently to ensure that each unit functions correctly in isolation.
These tests are crucial in embedded systems development to verify the functionality of software modules, drivers, and firmware components. Unit tests help detect defects early in the development process, allowing for faster debugging and ensuring the reliability and robustness of the embedded software.
Additionally, unit tests in embedded systems often involve testing the interaction between software and hardware components, such as sensors, actuators, and communication interfaces. These tests ensure that the software interacts correctly with the hardware platform and performs as expected in the embedded environment.
Types
- Unit Testing: Unit testing involves testing individual units or components of software in isolation. These units can be functions, methods, modules, or classes. Unit tests verify the correctness of the smallest units of code and ensure that they behave as expected.
- Integration Testing: Integration testing involves testing the interactions between different units or components of software. In embedded systems, this can include testing the integration of software modules, drivers, and firmware components to ensure that they work together correctly.
- System Testing: System testing involves testing the entire embedded system as a whole. This includes testing the system’s functionality, performance, reliability, and compatibility with external systems or devices. System testing verifies that the embedded system meets its requirements and performs as expected in its intended environment.
- Acceptance Testing: Acceptance testing involves testing the embedded system from the perspective of end-users or stakeholders. This type of testing validates that the system meets the user’s requirements and expectations. Acceptance testing may include functional testing, usability testing, and other tests to ensure that the embedded system meets the needs of its users.
Software Testing
- What is Unit Testing?
- What is Functional Testing?
- What is a Test Sequence?
- What is a Test Case File (TCF)?
- What is Code Coverage?
- What is a Regression Report?
Code Coverage
- If you have questions like what is function coverage?
- what is conditional coverage? What is decision coverage? here your answer.
Functional Coverage
- Functional coverage is a measure of what functionalities/features of the design have been exercised by the tests.
- The functions in the source code that are called and executed at least once.
Statement Coverage
- The number of statements that have been successfully validated in the source code.
Path Coverage
- The flows containing a sequence of controls and conditions that have worked well at least once.
Conditional Coverage
- Condition coverage is also known as Predicate Coverage in which each one of the Boolean expression have been evaluated to both TRUE and FALSE.
- Eg: The Boolean expressions that are validated and that executes both TRUE and FALSE as per the test runs
Decision Coverage
- Decision coverage or Branch coverage is a testing method, which aims to ensure that each one of the possible branch from each decision point is executed at least once and thereby ensuring that all reachable code is executed.
- The decision control structures (loops, for example) that have executed fine.
UNIT Test cases Examples
How many UT test cases need for below if loop with three condition?
char ArunEworld_IsNewPostAvailable()
{
bool AEW_IsNewPostAvailable = false;
if (AEW_IsPublished
&& AEW_IsReviewed
&& AEW_IsThisMonth)
{
AEW_IsNewPostAvailable= true;
}
return AEW_IsNewPostAvailable;
}
In the above code
- ArunEworld_IsNewPostAvailable() is the function name. this function return the true or false based on any new post available in website.
- AEW_IsNewPostAvailable is local boolean variable and AEW means ArunEworld
- AEW_AEW_IsPublished is global boolean variable
- AEW_AEW_IsReviewed is global boolean variable
- AEW_AEW_IsThisMonth is global boolean variable
The below are the all combination of AEW_IsPublished, AEW_IsReviewed, AEW_IsThisMonth variable values.
- T T T
- T T F
- T F T
- T F F
- F F F
- F F T
- F T F
- T F F
void UTest_ArunEworld_IsNewPostAvailable()
{
//Setup-1
AEW_IsPublished = true;
AEW_IsReviewed = true;
AEW_IsThisMonth = true;
AEW_IsNewPostAvailable = false;
//Execution of setup-1
ArunEworld_IsNewPostAvailable();
//Verification-1
TEST_ASSERT_EQUAL_MESSAGE(AEW_IsNewPostAvailable , 1, "UTest_ArunEworld_IsNewPostAvailable() T T T ");
//Setup-2
AEW_IsPublished = true;
AEW_IsReviewed = true;
AEW_IsThisMonth = false;
AEW_IsNewPostAvailable = true;
//Execution of setup-2
ArunEworld_IsNewPostAvailable();
//Verification-2
TEST_ASSERT_EQUAL_MESSAGE(AEW_IsNewPostAvailable , false, "UTest_ArunEworld_IsNewPostAvailable() T T F ");
//Setup-3
AEW_IsPublished = true;
AEW_IsReviewed = false;
AEW_IsThisMonth = true;
AEW_IsNewPostAvailable = true;
//Execution of setup-3
ArunEworld_IsNewPostAvailable();
//Verification-3
TEST_ASSERT_EQUAL_MESSAGE(AEW_IsNewPostAvailable , false, "UTest_ArunEworld_IsNewPostAvailable() T F T ");
//Setup-4
AEW_IsPublished = true;
AEW_IsReviewed = false;
AEW_IsThisMonth = false;
AEW_IsNewPostAvailable = true;
//Execution of setup-4
ArunEworld_IsNewPostAvailable();
//Verification-4
TEST_ASSERT_EQUAL_MESSAGE(AEW_IsNewPostAvailable , false, "UTest_ArunEworld_IsNewPostAvailable() T F F ");
//Setup-5
AEW_IsPublished = false;
AEW_IsReviewed = false;
AEW_IsThisMonth = false;
AEW_IsNewPostAvailable = true;
//Execution of setup-5
ArunEworld_IsNewPostAvailable();
//Verification-5
TEST_ASSERT_EQUAL_MESSAGE(AEW_IsNewPostAvailable , false, "UTest_ArunEworld_IsNewPostAvailable() F F F ");
//Setup-6
AEW_IsPublished = false;
AEW_IsReviewed = false;
AEW_IsThisMonth = true;
AEW_IsNewPostAvailable = true;
//Execution of setup-6
ArunEworld_IsNewPostAvailable();
//Verification-6
TEST_ASSERT_EQUAL_MESSAGE(AEW_IsNewPostAvailable , false, "UTest_ArunEworld_IsNewPostAvailable() F F T ");
//Setup-7
AEW_IsPublished = false;
AEW_IsReviewed = true;
AEW_IsThisMonth = false;
AEW_IsNewPostAvailable = true;
//Execution of setup-7
ArunEworld_IsNewPostAvailable();
//Verification-7
TEST_ASSERT_EQUAL_MESSAGE(AEW_IsNewPostAvailable , false, "UTest_ArunEworld_IsNewPostAvailable() F T F ");
//Setup-8
AEW_IsPublished = true;
AEW_IsReviewed = false;
AEW_IsThisMonth = false;
AEW_IsNewPostAvailable = true;
//Execution of setup-8
ArunEworld_IsNewPostAvailable();
//Verification-8
TEST_ASSERT_EQUAL_MESSAGE(AEW_IsNewPostAvailable , false, "UTest_ArunEworld_IsNewPostAvailable() T F F ");
}