Confused on project structure w/ CppUTest integration

137 views
Skip to first unread message

Shanedora

unread,
Nov 26, 2022, 5:46:37 PM11/26/22
to cpputest
Hi ~ 

Starter project says to download the starter project, renaming it to unit-tests into the root level of my project. In the section "Run Tests w/ Installed Toolchain" it tells me to download/build the framework itself somewhere in the root level too (or near it). Really confused why I should download/build the framework in my project directory. Doing so makes me feel like I have all this framework code in my project now that isn't relevant to my project. Is there some critical point here i'm missing?

I feel like my project structure is unorganized. I was kind of thinking about installing/building the framework elsewhere outside my project and then setting my project up like the following. Unfortunately, I'm fairly new to test frameworks so what might you recommend here? 

└── pjx_test/
    ├── Makefile (my project specific makefile)
    ├── src/
        ├── foo.c
        ├── foo.h
        ├── main.c
    └── unit-tests/
        └── makefile
        └── tests/
            ├── foo_unit_tests.cpp

Last question, and this might seem kind of odd, but I presume I can keep my project specific Makefile that builds my executable? What i'm trying to say is the cpputest makefile isn't suppose to take over (or serve) as the only makefile in my project correct? 

Thank you for your time  ~ S

James Grenning

unread,
Nov 27, 2022, 1:15:12 PM11/27/22
to 'Shanedora' via cpputest

Hi ~ S

Are you asking about the cpputest-starter-project found on my GitHub account?

If so...

Regarding putting the test framework in your project directory

I suggest putting the framework in your repo so you can recreate a particular test runner. In a year, or two, for more you may need to look into a prior test executable. If the test framework is in your repo, you'll be able to. You do not have to follow this advice. Integrating the framework into your project directory may be helpful if you are doing a native test build. There are other ways to accomplish the same thing.

Control your test build with Docker

These days, I prefer using docker. Docker helps to control the complete test build, including gcc and cpputest versions. You can see how that is done in the Dockerfile in the cpputest-starter-project.

You can use my pre-built docker image jwgrenning/cpputest-runner.

Regarding project structure

The structure is basically the same as you suggest, but missing the context of your project repo. The directory names

  • example-include - example interface defining header files
  • example-src - example production source files
  • example-platform - example production source with platform dependencies

are chose to not interfere with already existing names you might be using like

  • <your-project-home>/include - interface defining header files
  • <your-project-home>/src - production source files
  • <your-project-home>/platform - production source with platform dependencies

Once you have the examples running, you can transition over to your directories.

Regarding your project directory, you should consider separating header files that define interfaces from the src directory. If you ever need override an include file, you can't of the .h file included in the .c file are in the same directory. You should not need to do that often, but it is a good idea generally to separate interface from implementation.

Regarding production and test makefiles

You are right. Separate your product build from the test build.

Hope that helps!

I'll be updating the cpputest-starter-project README file, later today or tomorrow.

James


James Grenning -- Author of TDD for Embedded C
Join my live-via-the-web or self-paced TDD Training
wingman software
wingman-sw.com -- blog -- @jwgrenning -- facebook

--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cpputest/7f6eea5b-b761-4afa-ab93-93a5c26145d6n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages