Giter Site home page Giter Site logo

Comments (4)

mvandervoord avatar mvandervoord commented on August 27, 2024 3

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.

jwalkerbg avatar jwalkerbg commented on August 27, 2024

You may try ceedling package.
https://github.com/ThrowTheSwitch/Ceedling

from unity.

emidttun avatar emidttun commented on August 27, 2024

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.

emidttun avatar emidttun commented on August 27, 2024

Thanks Mark, that answers my question! Think I might stick to one runner per test module :)

from unity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.