Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #138334

Re: Unit test in C and breaking dependencies

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: Unit test in C and breaking dependencies
Date 2018-11-28 15:24 +1300
Message-ID <g66ci9F8pfeU2@mid.individual.net> (permalink)
References <pt11qe$es$1@dont-email.me>

Show all headers | View raw


On 21/11/2018 02:22, pozz wrote:
> I couldn't understand if the module under test is compiler two times:
> one for production code and the other for the test. I think it would be
> better to compile it only one time, for production code *and* tests. So
> you are sure you are testing the code that really will be in production.

Why wouldn't the code that really be in production?  Unit tests test 
logic, not target specific behaviour.

> So I think it should be better to link the test executable with the same
> object files generated during normal build for production code.

Which is often the case where the build environment is the same platform 
as the target.  If your policy is to disable assertions in production, 
then the waters become more muddy.

> One suggestion I read is to create a static library with all object
> files. The production executable and test executable are created linking
> this static library.

Common practice, however there are likely to be more than one library, 
or the libraries my be dynamic.

> This approach can be used to break and replace dependecies of a module
> under test. Indeed, if you specify the test doubles (replacing modules)
> before static library to the linker, it will use the test doubles
> instead of real modules.
> 
> Is it your preferred method? Are there other better ways?

Using dynamic libraries allows for function interposition which makes 
mocking easier.

-- 
Ian.

Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Unit test in C and breaking dependencies pozz <pozzugno@gmail.com> - 2018-11-20 14:22 +0100
  Re: Unit test in C and breaking dependencies James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-11-20 09:07 -0500
  Re: Unit test in C and breaking dependencies Thiago Adams <thiago.adams@gmail.com> - 2018-11-21 04:38 -0800
    Re: Unit test in C and breaking dependencies Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-11-21 12:59 +0000
      Re: Unit test in C and breaking dependencies Thiago Adams <thiago.adams@gmail.com> - 2018-11-21 05:35 -0800
        Re: Unit test in C and breaking dependencies Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-11-21 20:50 +0000
          Re: Unit test in C and breaking dependencies Thiago Adams <thiago.adams@gmail.com> - 2018-11-22 04:10 -0800
            Re: Unit test in C and breaking dependencies Anton Shepelev <anton.txt@g{oogle}mail.com> - 2018-11-22 15:30 +0300
              Re: Unit test in C and breaking dependencies Thiago Adams <thiago.adams@gmail.com> - 2018-11-22 04:44 -0800
            Re: Unit test in C and breaking dependencies Thiago Adams <thiago.adams@gmail.com> - 2018-11-22 04:35 -0800
            Re: Unit test in C and breaking dependencies Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-11-22 17:08 +0000
              Re: Unit test in C and breaking dependencies Thiago Adams <thiago.adams@gmail.com> - 2018-11-23 03:08 -0800
                Re: Unit test in C and breaking dependencies Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-11-24 05:51 +0000
                Re: Unit test in C and breaking dependencies Chad <cdalten@gmail.com> - 2018-11-24 03:35 -0800
                Re: Unit test in C and breaking dependencies Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-11-24 12:50 +0000
                Re: Unit test in C and breaking dependencies Chad <cdalten@gmail.com> - 2018-11-26 07:20 -0800
                Re: Unit test in C and breaking dependencies Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-11-27 14:32 +0000
                Re: Unit test in C and breaking dependencies Ian Collins <ian-news@hotmail.com> - 2018-11-28 15:18 +1300
            Re: Unit test in C and breaking dependencies Thiago Adams <thiago.adams@gmail.com> - 2018-11-29 09:16 -0800
        Re: Unit test in C and breaking dependencies Wouter Verhelst <w@uter.be> - 2018-11-23 09:21 +0100
          Re: Unit test in C and breaking dependencies Thiago Adams <thiago.adams@gmail.com> - 2018-11-23 03:16 -0800
            Re: Unit test in C and breaking dependencies Thiago Adams <thiago.adams@gmail.com> - 2018-11-23 03:18 -0800
            Re: Unit test in C and breaking dependencies Anton Shepelev <anton.txt@g{oogle}mail.com> - 2018-11-23 15:27 +0300
              Re: Unit test in C and breaking dependencies Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-11-23 06:42 -0800
  Re: Unit test in C and breaking dependencies Ian Collins <ian-news@hotmail.com> - 2018-11-28 15:24 +1300

csiph-web