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 7578581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:28:00+00:00 2026-05-30T17:28:00+00:00

I’ve got a UnitTest++ test class, which allows me to test that a class

  • 0

I’ve got a UnitTest++ test class, which allows me to test that a class is parsing some strings correctly. Before running the test, I create a fixture that contain several strings to be tested by various functions in a loop. It seems to work fine, but the problem is that, in case of error, UnitTest++ will always give me the same error line, so I won’t know which string exactly is causing the issue.

For example, it will output:

"[UnitTest++] ..\trunk\tests\Test_ChineseUtil.cpp(46): error: Failure in ParsePinyinT: ChineseUtil::parsePinyinT(pinyinT) == pinyinN" 

But that doesn’t tell me which string is not being parsed correctly.

So what I would like is to set some custom error message when a test fails (in that particular case, I would give it the first item in my array). Basically, I need something like:

CHECK(theTest, "my error message")

Is there such function in UnitTest++? Or maybe there is a better way to do what I’m trying to do?

For information, here is the code of my class:

#include <third_party/unittest++/UnitTest++.h>

#include <Application.h>
#include <ChineseUtil.h>

using namespace hanzi;

namespace chineseUtilTests {

class PinyinFixture {

public:

    PinyinFixture() {
        ChineseUtil::initialize();

        testData << "third tone" << QString::fromUtf8("wo3") << QString::fromUtf8("wǒ");
        testData << "no tone" << QString::fromUtf8("wo") << QString::fromUtf8("wo");
        testData << "second tone" << QString::fromUtf8("guo2") << QString::fromUtf8("guó");
        testData << "first tone" << QString::fromUtf8("jia1") << QString::fromUtf8("jiā");
        testData << "fifth tone" << QString::fromUtf8("jia5") << QString::fromUtf8("jia");
        testData << "two dots" << QString::fromUtf8("nu:") << QString::fromUtf8("nü");
        testData << "two dots and tone" << QString::fromUtf8("nu:3") << QString::fromUtf8("nǚ");
    }

    ~PinyinFixture() {

    }

    QStringList testData;

};

TEST_FIXTURE(PinyinFixture, ParsePinyinN) {
    for (int i = 0; i < testData.size(); i++) {
        QString pinyinN = testData[i][1];
        QString pinyinT = testData[i][2];
        CHECK(ChineseUtil::parsePinyinN(pinyinN) == pinyinT); 
    }
}

TEST_FIXTURE(PinyinFixture, ParsePinyinT) {
    for (int i = 0; i < testData.size(); i++) {
        QString pinyinN = testData[i][1];
        QString pinyinT = testData[i][2];
        CHECK(ChineseUtil::parsePinyinT(pinyinT) == pinyinN); 
    }
}

} // chineseUtilTests
  • 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-05-30T17:28:02+00:00Added an answer on May 30, 2026 at 5:28 pm

    If your class has an equality operator, you should be able to, instead of typing

    CHECK(something == something_else);
    

    use

    CHECK_EQUAL( something, something_else);
    

    The fact that your classes allow a == makes me thing you can do this. If the test fails, you should get something along the lines of “Expected something but got something else”.

    If you need more information, there are a couple other things you can do.

    One is to add your own custom output in the test. If you need to know the value of i specifically, you can add a printout of i before each CHECK. However, this output may be too lengthy for large loops, so you can add your check a second time.

    CHECK(ChineseUtil::parsePinyinN(pinyinN) == pinyinT);
    if ( ChineseUtil::parsePinyinN(pinyinN) != pinyinT )
    {
        cout << "Your own custom message " << i << endl;
    }
    

    Another possibility is to modify the source code of UnitTest++ itself, then recompile the library. While I don’t know the exact steps to do what you want to do, I’ve modified UnitTest++/src/Checks.h to improve the output of CHECK_ARRAY2D_CLOSE so it was more readable.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I am doing a simple coin flipping experiment for class that involves flipping a
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.