473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

any tricks to help us from forgetting to call test functions?

Hi. I have a file of test functions.

int test1() {
return 0;
}
int test2()
return 0;
}

There is another function that calls all the tests.

int doall() {
test1();
test2();
}

Problem is that if I add more tests, I may forget to update doall. Anyone
have any tricks to help me remember to update doall? (Of course, I can test
my code thoroughly, but I'd rather catch silly omissions earlier with the
compiler's help.)

Here is my present trick, but it uses macros.
#include <vector>
#include <numeric>
std::vector<int (*)()> testfuncs;
struct AddTest
{
AddTest(int (*func)())
{
testfuncs.push_back(func);
}
};

#define NEW_TEST(name) int name(); \
AddTest AddTest_##name(&name); \
int name()

struct callfunc
{
int operator()(int previousresult, int (*func)()) const
{
int newresult = (*func)();
return newresult + previousresult;
}
};

////////////////////////////////////////////////////////////////////////////
////

NEW_TEST(test1) {
return 0;
}
NEW_TEST(test2) {
return 0;
}
int doall()
{
int out = 0;
std::accumulate(testfuncs.begin(), testfuncs.end(), out, callfunc());
return out;
}

Jul 22 '05 #1
1 1101
Siemel Naran wrote:
NEW_TEST(test1) {
return 0;
}
NEW_TEST(test2) {
return 0;
}
int doall()
{
int out = 0;
std::accumulate(testfuncs.begin(), testfuncs.end(), out, callfunc());
return out;
}


Mike Feathers and I have that pattern:

http://www.xpsd.org/cgi-bin/wiki?NanoCppUnit

BTW it's not a matter of "forgetting", if you start each feature with a
failing test, because if nothing fails you will realize your test didn't
call. It's a matter of unifying the point of change in a program.

Now, before you read the link, how would you pass a test suite, with
setUp(), tearDown(), and member variables into that macro?

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Shailesh Humbad | last post by:
I just posted an article I wrote called ASP Speed Tricks. It covers techniques to optimize output of database data in HTML, for both simple tables and complex tables. More advanced ASP authors...
13
by: Roger | last post by:
Can anyone tell me what is the difference between these two? class nodeType { int data; nodeType *link; }; This is the first one:
7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
822
by: Turamnvia Suouriviaskimatta | last post by:
I 'm following various posting in "comp.lang.ada, comp.lang.c++ , comp.realtime, comp.software-eng" groups regarding selection of a programming language of C, C++ or Ada for safety critical...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
3
by: Ralph A. Moritz | last post by:
Hi everyone, first of all, sorry for using Google to post. I know some people find this offensive, but as I am stuck behind a firewall, I don't have a choice. I am reading ``The Practice of...
1
by: sommarlov | last post by:
Hi everyone >From one of our systems an xml file is produced. I need to validate this file before we send it to an external system for a very lenghty process. I cannot change the xml file layout....
13
by: Jennifer.Berube | last post by:
well I'm not sure how to go about making my SQL connection string... The code below is what I need to replace with my SQL connection...I just don't know if that code is for DSN or access... I...
10
by: CuTe_Engineer | last post by:
hii, i have cs assignment i tried to solve it but i still have many errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote the prog. i just wanna you to show me my mistakes ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.