472,978 Members | 2,271 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

unit--, a unit test framework for C++

hi, fellows

I'd like to intruduce a new unit test framework for C++
freely available at:

http://unit--.sourceforge.net/

It does not need bothering test registration, here is an example

// --- begin code ---
#include "unit--.h"

testSuite(MySuite);

testCase(CompareCase, MySuite)
{
int x = 1;
int y = x + 2;
assertTrue(x < y);
}
// --- end code ---

besides, unit-- is implemented entirely in std C++, thus is portable
across different platforms and compilers

Apr 15 '06 #1
5 2443
VvanN wrote:
I'd like to intruduce a new unit test framework for C++
freely available at:

http://unit--.sourceforge.net/

It does not need bothering test registration, here is an example
Righteous. CppUnit mires itself in endless test registration issues, instead
of simply using macros to achieve the Test Collector pattern.
// --- begin code ---
#include "unit--.h"

testSuite(MySuite);

testCase(CompareCase, MySuite)
{
int x = 1;
int y = x + 2;
assertTrue(x < y);
}
// --- end code ---
Suppose I had two suites and wanted to run the same case over both suites?

http://c2.com/cgi/wiki?AbstractTest

Suppose a test case uses std::basic_string<>. How would I run the test case
twice, once with char and again with wchar_t?
besides, unit-- is implemented entirely in std C++, thus is portable
across different platforms and compilers


Contrarily, at error time, your editor should present the option to navigate
to a failure, the same as syntax errors.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 15 '06 #2
"Phlip" <ph******@yahoo.com> writes:
VvanN wrote:
I'd like to intruduce a new unit test framework for C++
freely available at:

http://unit--.sourceforge.net/

It does not need bothering test registration, here is an example


Righteous. CppUnit mires itself in endless test registration issues, instead
of simply using macros to achieve the Test Collector pattern.


Those interested in such things might also check out the Boost unit
test framework <http://www.boost.org/libs/test/doc/index.html>; I've
had very good results using it.

----------------------------------------------------------------------
Dave Steffen, Ph.D. Fools ignore complexity.
Software Engineer IV Pragmatists suffer it.
Numerica Corporation Some can avoid it.
ph (970) 419-8343 x27 Geniuses remove it.
fax (970) 223-6797 -- Alan Perlis
dgsteffen at numerica dot us
Apr 17 '06 #3
Dave Steffen wrote:
Those interested in such things might also check out the Boost unit
test framework <http://www.boost.org/libs/test/doc/index.html>; I've
had very good results using it.


That one always squicks me out.

Specifically, it relies on excessive test registration calls, and doesn't
use any Test Collector, despite otherwise freely abusing macros...

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 17 '06 #4
Phlip wrote:
VvanN wrote:
I'd like to intruduce a new unit test framework for C++
freely available at:

http://unit--.sourceforge.net/

It does not need bothering test registration, here is an example


Righteous. CppUnit mires itself in endless test registration issues, instead
of simply using macros to achieve the Test Collector pattern.
// --- begin code ---
#include "unit--.h"

testSuite(MySuite);

testCase(CompareCase, MySuite)
{
int x = 1;
int y = x + 2;
assertTrue(x < y);
}
// --- end code ---


Suppose I had two suites and wanted to run the same case over both suites?

http://c2.com/cgi/wiki?AbstractTest

Suppose a test case uses std::basic_string<>. How would I run the test case
twice, once with char and again with wchar_t?

we might consider that they are different test cases,
but they have code in common.

"extract method"
(http://www.refactoring.com/catalog/extractMethod.html)
could work for this scenario.
assertTrue() can effect in functions invoked by a testCase

here is an example:

// --- begin code ---
#include <vector>
#include <numeric>
#include <algorithm>
#include "../unit--.h"

testSuite(TemplateSuite)

template <typename T>
void testAlgorithms()
{
using namespace std;
using namespace unit_minus;
vector<T> ve(100, 1);
partial_sum(ve.begin(), ve.end(), ve.begin());

assertTrue(ve.size() > 0);
assertTrue(1 == ve[0]);
for (unsigned i = 1; i < ve.size(); ++i) {
assertTrue(ve[i - 1] + 1 < ve[i]);
}
}

namespace {
testCase(IntCase, TemplateSuite)
{
testAlgorithms<int>();
}

testCase(UnsignedCase, TemplateSuite)
{
testAlgorithms<unsigned>();
}

} // namespace
// --- end code ---
besides, unit-- is implemented entirely in std C++, thus is portable
across different platforms and compilers


Contrarily, at error time, your editor should present the option to navigate
to a failure, the same as syntax errors.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!


Apr 28 '06 #5
VvanN wrote:
testSuite(TemplateSuite)

template <typename T>
void testAlgorithms()
{
using namespace std;
using namespace unit_minus;
vector<T> ve(100, 1);
partial_sum(ve.begin(), ve.end(), ve.begin());

assertTrue(ve.size() > 0);
assertTrue(1 == ve[0]);
for (unsigned i = 1; i < ve.size(); ++i) {
assertTrue(ve[i - 1] + 1 < ve[i]);
}
}

namespace {
testCase(IntCase, TemplateSuite)
{
testAlgorithms<int>();
}

testCase(UnsignedCase, TemplateSuite)
{
testAlgorithms<unsigned>();
}

} // namespace
// --- end code ---


Thanks!

One use of AbstractTest is to turn a cases' setUp() and tearDown() into an
abstract factory. setUp() will create a different type, so a common case
body can work across a range of types. Your code doesn't need this effect
because your assertions are not members of the basic TestCase class.

(Assertions are typically macros, so I mean macros are members when they use
member variables inside them.)

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Apr 28 '06 #6

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

Similar topics

3
by: Alexander Eisenhuth | last post by:
Hello alltogether, I'm new to this group, so please tell me, if there is a better place to ask ... I'm also new to the TDD (test driven development) aproach. I just started to learn about the...
4
by: sylcheung | last post by:
Hi, Does anyone has any suggestion for Unit Test Framework for c++ program? Is there any framework which let me use some script languages (e.g. python) to write the test cases to test c++...
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
2
by: Pesso | last post by:
Hi I'm not sure what's the appropriate group to post this question so here we go. We are looking for a dotNET based test framework like STAF (Java based). We prefer non-commercial open source...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.