Dynamic Verification: Unit Testing

VectorCAST Automates Unit Testing for Safety-Critical Embedded Code

Dynamic verification executes software against defined test cases and measures actual runtime behavior. It confirms that functions return correct results under normal conditions, boundary cases, and error states, and produces the structural coverage data that ISO 26262, DO-178C, IEC 61508, and IEC 62304 require as verification evidence.

Unit testing is where that process starts. Each function, module, class, and component is verified in isolation against its specification before integration begins. Defects caught at this stage cost a fraction of defects caught during integration or in the field, and the traceability records produced here form the foundation of the compliance case.

The Testing Workflow

The dynamic verification workflow in safety-critical development follows a defined sequence. Before testing begins, requirements are imported and linked to test cases, establishing the traceability baseline the applicable standard requires. Test environments isolate the software under test using stubs and mocks to replace unavailable dependencies. Tests execute on the host, the target, or both, with coverage measured throughout. Results feed back into the requirements management system, completing the bidirectional record that auditors review.

What Unit Testing Verifies

A thorough unit test suite exercises more than the expected inputs. Each test case is written against a specific requirement and covers:

  • Normal inputs and expected outputs
  • Boundary conditions and off-by-one cases
  • Error inputs and invalid states
  • Overflow and underflow conditions relevant to the data types involved
  • Behavior when dependencies return unexpected values

     

In safety-critical development, each test case traces back to a specific requirement it was designed to verify. Bidirectional traceability from requirement to test case to result is mandatory evidence under DO-178C and ISO 26262.

Requirements Traceability

Requirements-based testing is mandatory under ISO 26262, DO-178C, IEC 61508, and IEC 62304. Each test case must trace back to a specific requirement it was designed to verify, and test results must link back to those requirements bidirectionally. This record demonstrates that all requirements have been tested and that no test exists without a corresponding requirement.

VectorCAST's Requirements Gateway connects to external requirements databases, imports requirements into the test environment, and allows test cases to be linked to them directly. After execution, results and coverage metrics are exported back to the requirements management tool. Requirements without test coverage are immediately visible, as are test cases with no linked requirement.

Test Environment Construction

Embedded software under test typically depends on hardware interfaces, operating system services, or other software components that are unavailable or impractical to invoke during unit testing. Stubs replace those dependencies, allowing the unit under test to be exercised in isolation with full control over what each dependency returns.

VectorCAST generates stubs automatically for all dependencies when a test environment is constructed. Stubs can be enabled, disabled, or configured per test case to return specific values. Probe points extend this control further, allowing values to be injected at any point in the unit under test to reach code paths that would otherwise require specific hardware conditions or fault states to trigger. VectorCAST also supports stubbing of template function instantiations, including both explicit and implicit instantiations of template class members, which is important for C++ codebases where this pattern is common.

Code Coverage

Code coverage measures what proportion of the executable code is exercised by the test suite. Safety standards prescribe minimum coverage levels based on the criticality of the software being developed.

  • Statement coverage ensures every executable line has been run at least once
  • Branch coverage confirms every decision point has taken each possible outcome
  • MC/DC (Modified Condition/Decision Coverage) proves that each Boolean condition in a decision independently affects the outcome, the most rigorous structural criterion and a requirement for DO-178C Level A and ISO 26262 ASIL D software

VectorCAST measures all of these coverage types and includes Industry Modes that automatically select the correct coverage criteria for a given standard and safety integrity level. Coverage results are certified by TÜV.

Host and Target Testing

Unit tests are typically developed and run first on the host machine for speed and control. Rapid iteration, immediate feedback, and easy debugging make the host the right environment for building and refining the test suite. When testing on the host the target compiler is not used, so any compiler-specific behavior must be verified separately on the target.

VectorCAST makes it straightforward to run the same test cases on the target hardware. Test environments are developed on the host and executed on the target using Runtime Support Packages (RSP) available for many cross-compilers and real-time operating systems. Coverage measurement, traceability, and reporting apply equally in both environments.

Automated Test Generation

Writing test cases manually for a large embedded codebase is time-consuming and prone to gaps. VectorCAST's Automated Test Generation (ATG) produces an initial set of test cases directly from source code, targeting boundary conditions and code paths that manual authoring commonly misses. Engineers review and extend the generated tests rather than writing them from scratch.

Teams that prefer writing test code directly can use Coded Tests, which provides xUnit-style test authoring using GoogleTest-compatible syntax while retaining access to VectorCAST's coverage measurement, traceability, and CI/CD integration.

VectorCAST

VectorCAST is Vector's dynamic testing and test automation platform for embedded C, C++, and Ada software. It automates test environment construction, generates and manages test cases, executes tests on host and target, measures structural coverage, and produces auditable reports.

Key capabilities include:

  • Automatic test environment setup with generated stubs, mocks, and test harnesses
  • Automated Test Generation (ATG) to produce initial test cases directly from source code
  • Coded Tests for xUnit-style test authoring compatible with GoogleTest syntax
  • Requirements Gateway for bidirectional traceability to external requirements databases
  • Change-Based Testing to re-execute only tests affected by code changes
  • VectorCAST Test Explorer extension for Visual Studio Code
  • CI/CD integration including Jenkins, Azure DevOps, and GitLab
Next: Integration Testing
Once individual components are verified, integration testing confirms that they interact correctly at their boundaries. VectorCAST measures data and control coupling coverage as required by DO-178C and related standards.