Comments (4)
Eirik:
There isn't an automated way of doing this that is included with Unity. For
the most part, we stick to the one executable per test file theory. There
are a couple of reasons for this. I'll explain those and then tell you how
you can work around them if you decide this is something you still want to
do.
(1) Multiple units in the same file rarely works well you have modules that
would normally interact with each other. This might mean CMock-generated
mocks or hand-created stubs or other things... but the problem is the same:
you need a real version of a function AND a fake version of a function to
get compiled into the same app. This requires a lot of linker magic and
often results in release code with added complexity just to support the
testing.
(2) Even if you're only selecting files that are unrelated, it's a solution
that doesn't scale well. As projects grow, you're going to want to have
your build system only run tests for changed modules, etc. This is really
simple with one to one relationships, but becomes a mapping headache for
more complex systems.
Those things being said, it IS possible. A test runner clearly doesn't do a
LOT. You could manually create one that basically includes unity and tests,
then has a main function which calls all your tests. It could looks
something like this:
//Yes, including C files. I really dislike this, but it beats externing
every single test function you might need
#include "TestA.c"
#include "TestB.c"
//There can be only one of these... so probably in this file?
void setUp(void) { ... }
void tearDown(void) { ... }
int main(void) {
}
UNITY_BEGIN( );
//you'll have to add your tests manually
RUN_TEST( TestA_test1 );
RUN_TEST( TestA_test2 );
RUN_TEST( TestB_test1 );
return UNITY_END( );
}
This should work, but will give you one problem: it's going to use the NAME
of your runner file in your errors, instead of the name of the test that
failed. To fix this, you need to add a further complication of separating
your runs:
int main(void) {
}
int retval;
UnityBegin( "TestA.c" );
//you'll have to add your tests manually
RUN_TEST( TestA_test1 );
RUN_TEST( TestA_test2 );
retval = UNITY_END( );
if (retval)
return retval;
UnityBegin( "TestB.c" );
//you'll have to add your tests manually
RUN_TEST( TestB_test1 );
return UNITY_END( );
}
The complication to this method is going to be that you are going to get a
separate summary for each test file, but at least they all run together.
I think that gives enough information so you can see a bit about what is
going on under the hood at least? If you run into further questions, feel
free to ask.
Good luck
Mark
from unity.
You may try ceedling package.
https://github.com/ThrowTheSwitch/Ceedling
from unity.
I'm not really looking for a build system, the point is just to have one test runner (one main() function) for several test files. Mainly as a way of balancing total number of build targets in a code base and the size of the test files.
from unity.
Thanks Mark, that answers my question! Think I might stick to one runner per test module :)
from unity.
Related Issues (20)
- Possibly typo in test_unity_integers_64.c and test_unity_arrays.c HOT 1
- Avoid running the setup for some specific tests HOT 3
- #529 still unfixed after merge HOT 2
- PlatformIO failing to parse manifest on install. HOT 1
- Game thing.com HOT 1
- How do I rename the `setUp` and `tearDown` functions? HOT 2
- Build fails with -Werror=missing-declarations when UNITY_USE_COMMAND_LINE_ARGS is enabled HOT 1
- XML/JSON based report generating? HOT 2
- Errr how u use this HOT 1
- Can you code on iPad using this app?
- I'm in secondary school first grade sooo i have no idea what I'm doing (I'm trying to tell but not expose my age) HOT 1
- Can you use this app to code on iPad?
- ssize_t asserts are missing
- Add Example for Testing using CMake
- Build fails when not using UNITY_USE_COMMAND_LINE_ARGS
- Feature Request: Support asymmetric range assertions HOT 2
- Some codes failed `-Werror=float-equal` compiler flag, please fix it.
- UNITY_NORETURN redefines noreturn, uses stdnoreturn.h which can break compatibility with C23 and is being defined when unnecessary HOT 1
- Generic assertion HOT 3
- Invalid file name reported HOT 18
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unity.