Unit Testing for hybrid systems
Unit testing is a foundational phase in the software development lifecycle, aimed at validating individual functions, modules, or components. In the context of hybrid embedded/cloud systems, unit testing takes on unique characteristics, as the two systems are often developed in parallel using different architectures, languages and tools. This article dives into the specific tools and strategies that make unit testing effective for these two different systems.
If you are not familiar with hybrid embedded/cloud systems, refer to the previous article Hybrid Embedded/Cloud systems.
For a general overview of the test levels required to ensure good test coverage for such systems, you can read the previous article Test levels for hybrid embedded/cloud systems.
Unit Testing in parallel: embedded and cloud
In hybrid systems, unit testing activities occur in parallel for the embedded and cloud software. These two domains usually have distinct development environments and tools:
Embedded software: typically developed in C or C++, embedded software benefits from frameworks tailored for these languages.
Cloud software: often developed using high-level languages like Python, the cloud side has its own suite of testing tools and frameworks.
The goal of unit testing in this context is to isolate and validate individual components in both systems while ensuring they align with the overall system behavior.
Common tools for embedded libraries Unit Testing
For C or C++ libraries, GoogleTest is a widely used framework for unit testing. It provides a comprehensive environment for writing, organizing, and running tests. Alongside GoogleTest, gMock is often used to mock dependencies, enabling isolated testing of embedded modules.
These tools are particularly useful for testing embedded system functions and validating their response to simulated inputs without needing the full system in place.
Common tools for cloud libraries Unit Testing
Assuming cloud modules are built in Python, frameworks like unittest and pytest are excellent options:
unittest: built into Python, it provides a solid foundation for writing and executing tests.
pytest: known for its simplicity and flexibility, pytest is a preferred choice due to its fixture system, which simplifies setting up and tearing down tests.
To measure test coverage, you can use pytest-cov, a plugin for pytest that generates detailed coverage reports. In cases where cloud modules interact with external services like AWS, mocking frameworks like moto are invaluable. Moto allows you to simulate AWS services in your tests, making it easier to validate cloud modules without accessing real cloud resources.
Automating Unit Tests in CI Pipelines
Unit tests for both embedded and cloud systems can be integrated into the repository’s CI pipeline to ensure continuous validation of the codebase. This helps catch issues early and maintain high test coverage as the code evolves. Automated testing in CI pipelines also enables faster regression testing, ensuring that changes in the codebase do not introduce new bugs.
Final Thoughts
Unit testing is a crucial step in the development of hybrid embedded/cloud systems. By leveraging specialized tools for both embedded and cloud software, teams can ensure their individual modules function as expected before moving to more complex integration and system-level testing. Automating these tests within CI pipelines provides consistent validation, saving time and effort in the long run.
By ensuring robust unit testing, you establish a strong foundation for the entire hybrid system. This preparation allows higher-level testing activities to concentrate on their specific objectives, ensuring that each level addresses the aspects most critical to its purpose.