April 2011
Intermediate to advanced
356 pages
8h 55m
English
CMock[26] is a mock generator that is a companion to Unity. CMock generates test double functions that conform to the interface specified in a header file. Let’s see what CMock will generate if we give it IO.h:
| include/IO/IO.h | |
| | #ifndef D_IO_H |
| | #define D_IO_H |
| | #include <stdint.h> |
| | |
| | typedef uint32_t ioAddress; |
| | typedef uint16_t ioData; |
| | |
| | ioData IO_Read(ioAddress offset); |
| | void IO_Write(ioAddress offset, ioData data); |
| | |
| | #endif |
CMock generates a header file and a mock implementation. The h file looks a lot like the mock we handcrafted.
| mocks/cmock/MockIO.h | |
| | /* AUTOGENERATED FILE. DO NOT EDIT. */ |
| | #ifndef _MOCKIO_H |
| | #define _MOCKIO_H |
| | |
| | #include "IO.h" |
| | |
| | void MockIO_Init(void); |
| | void MockIO_Destroy(void); |
Read now
Unlock full access