LWN: Comments on "Unit testing with mock objects in C" https://lwn.net/Articles/558106/ This is a special feed containing comments posted to the individual LWN article titled "Unit testing with mock objects in C". en-us Thu, 02 Oct 2025 09:49:52 +0000 Thu, 02 Oct 2025 09:49:52 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Unit testing with mock objects in C https://lwn.net/Articles/818528/ https://lwn.net/Articles/818528/ Venkateshappa <div class="FormattedComment"> Hi,<br> Adding __attribute__((weak)) to the original source makes the code messy. Are there other ways like by setting --wrap attribute project level to wrap functions that are within the file where the function under test reside or any file?<br> <p> Thanks,<br> Venky<br> <p> </div> Fri, 24 Apr 2020 01:59:44 +0000 Unit testing with mock objects in C https://lwn.net/Articles/637626/ https://lwn.net/Articles/637626/ coroander Sometimes it is best to wrap a function that is within the file where the functions under test reside. In these cases, -wrap won't have any effect. However if the function to be wrapped is declared with <tt>__attribute__((weak))</tt> then in the unit test, the function can be redeclared (without the <tt>__wrap_</tt> prefix), and this binding overrides the weak binding in the code under test. Other than dropping the <tt>__wrap_</tt> prefix (and not having to add -wrap to the linker options), it works exactly the same. An excellent piece of software. Tue, 24 Mar 2015 07:25:34 +0000 Unit testing with mock objects in C https://lwn.net/Articles/559643/ https://lwn.net/Articles/559643/ mjthayer <div class="FormattedComment"> My problem with mock interfaces is that many interfaces do not lend themselves cleanly to being simulated. Case in point, the VirtualBox code which interacts with the X11 clipboard, which has a rather intricate communication protocol. Understanding the simulation code proved to be more work then testing manually. I am now trying the approach of wrapping those interfaces in another, higher level of interfaces more amenable to classical unit testing, and treating the code in-between them and the real ones as glue code - that is, it is not to be unit tested, but it should be simple enough that its correctness should be obvious, or at least straight forward enough that simple integration tests should show whether or not it is working without too many edge cases to consider.<br> </div> Fri, 19 Jul 2013 07:25:52 +0000