Partials
A Partial is your C code sliced and diced to expose elements for testing that you could not otherwise access without rewriting your source code. Think of Partials as a unit testing scalpel.
Partials are useful when you need to test:
staticorinlinefunctions — These become accessible to your test code without modifying your source.- File-scoped
staticvariables — Thestatickeyword is stripped, and the variable is automatically madeexternfor your test code with no changes to the source under test. - Function-scoped
staticvariables — These are promoted from function scope to module scope so they can be accessed in your test code just like file-scopedstaticvariables. - Same-module mocked functions — You can mix and match tested and mocked functions from the same source module. Partials allow mocking functions inside a module that are called by other functions inside the same module.
Tip
See the wondrous_forest
example available within Ceedling for a working example project
demonstrating Partials in action.
-
How Ceedling generates testable and mockable Partials from your C source under test with a step-by-step simple example.
-
What is a module? “Public” and “private” functions in a programming language that has no such terminology.
-
How to enable Partials in your project, include
ceedling.h, and an overview of directive macro categories. -
A complete end-to-end demonstration of Test Partials and Mock Partials.
-
- Generation macros used with
#includefor creating Partials. - Config macros for fine-tuning your Partials.
- Generation macros used with
-
How to test file-scoped and function-scoped
staticvariables via Partials.
Limitations of Partials
Partials are new to Ceedling with 1.1.0. Carving up C code is tricky business. Complex code may break Ceedling’s lexing or certain assumptions. Some issues may be bugs to be reported while others may be complexities that Partials are simply unable to resolve.