Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8772093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:57:22+00:00 2026-06-13T17:57:22+00:00

First whats the class I use if I want to setup a test like:

  • 0

First whats the class I use if I want to setup a test like:

class MyClassTests 
    setup()
    teardown()
    testDoingSomething()
    testDoingA()

Seems like the class to use is TestSuite?


So now I just created a very simple class:

# ParserUnitTests.h
#include <cppunit\TestFixture.h>;
#include <cppunit\extensions\HelperMacros.h>

class ParserUnitTests : public CppUnit::TestFixture {

public:
    void testCanDoUnitTest();
};

And its corresponding cpp:

#include "ParserUnitTests.h"

CPPUNIT_TEST_SUITE(ParserUnitTests);

void ParserUnitTests::testCanDoUnitTest() {
    CPPUNIT_ASSERT_EQUAL(1, 2, "Expected failure");
}

CPPUNIT_TEST(ParserUnitTests::testCanDoUnitTest);

I am getting errors like “expected a declaration” on the CPPUNIT_TEST_SUITE line… seems very different from where I come from … more modern languages … like JS/Python … Seems like here its more explicit? I must tell CppUnit which class/test cases to run? Ok, but whats causing the errors?

The code in the CppUnit cookbook is mainly snipplets and its hard to figure out what are the imports required and what should go where … perhaps someone can guide me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:57:23+00:00Added an answer on June 13, 2026 at 5:57 pm

    With some small changes your code should work.

    // ParserUnitTests.h
    #include <cppunit\TestFixture.h>;
    #include <cppunit\extensions\HelperMacros.h>
    
    class ParserUnitTests : public CppUnit::TestFixture {
    
        CPPUNIT_TEST_SUITE(ParserUnitTest);
        CPPUNIT_TEST(testCanDoUnitTest);
        CPPUNIT_TEST_SUITE_END();
    
    public:
        void testCanDoUnitTest();
    };
    
    CPPUNIT_TEST_SUITE_REGISTRATION( ParserUnitTest );
    

    and

    // ParserUnitTests.cpp
    #include "ParserUnitTests.h"
    
    void ParserUnitTests::testCanDoUnitTest() {
        CPPUNIT_ASSERT_EQUAL(1, 2, "Expected failure");
    }
    

    then you only need a main (which I copied just from the Cppunit cookbook)

    // main.cpp
    #include <cppunit/extensions/TestFactoryRegistry.h>
    #include <cppunit/ui/text/TestRunner.h>
    
    int main()
    {
        CppUnit::TextUi::TestRunner runner;
        CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
        runner.addTest( registry.makeTest() );
        bool wasSuccessful = runner.run();
        return !wasSuccessful;
    }
    

    So the only change is that you need to declare the test suite in the header file inside the TestFixture declaration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My first question here... I want to use an abstract class A from which
Just want to start out by saying this seems like a great site, hope
I'd like to use preventDefault on a parent element, but I don't want it
Begin Edit: Primarily I want my Clojure program to use a Java class. I've
First here's what I'm using and trying to do: the minimal setup for this
First let me tell you what I want to achieve. I want a layout
Its probarbly a simple 3-tier problem. I just want to make sure we use
First of all, just grant that I do in fact want the functionality of
Lets say I have two similar class: public class First { public static final
Possible Duplicate: C++ invoke explicit template constructor First imagine I have a class Data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.