1

I have Grenning's book. On page 20 he has the output from a unity example. It shows no passing tests, just ". . ." for each passing test.

I downloaded the unity source and am running it in a simulator for my target processor. I see every test case listed - passing ones and failing ones.

I don't see any option I can define in unity.h that would only print out the failing test cases and the summary. I have a lot of tests and my stdout window is really cluttered right now.

Is that some magic handled by the generate test runner ruby script that I am not using (in the auto or extras directories)? Or is there a basic option I am missing.

This is representative of what my output looks like now

C:[path]\ut_main.c:80:test_fred_condition_foo:PASS
C:[path]\ut_main.c:85:test_fred_condition_bar:FAIL: Expected 1
C:[path]\ut_main.c:90:test_fred_condition_baz:PASS
C:[path]\ut_main.c:95:test_fred_condition_qux

-----------------------
4 Tests 1 Failures 0 Ignored
FAIL

I'd rather it be like:

.
C:[path]\ut_main.c:85:test_fred_condition_bar:FAIL: Expected 1
. . 

-----------------------
4 Tests 1 Failures 0 Ignored
FAIL
4

1 回答 1

0

UnityConcludeTest()在 unity.c 中修改来解决这个问题。

是这样的:

void UnityConcludeTest(void)
{
    if (Unity.CurrentTestIgnored)
    {
        Unity.TestIgnores++;
    }
    else if (!Unity.CurrentTestFailed)
    {
        UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
        UnityPrint(UnityStrPass);
    }
    else
    {
        Unity.TestFailures++;
    }

    Unity.CurrentTestFailed = 0;
    Unity.CurrentTestIgnored = 0;
    UNITY_PRINT_EOL;
}

我把它改成了这个

void UnityConcludeTest(void)
{
    if (Unity.CurrentTestIgnored)
    {
        UNITY_PRINT_EOL;
        Unity.TestIgnores++;
    }
    else if (!Unity.CurrentTestFailed)
    {
#ifdef UNITY_QUIET
        UnityPrint(".");
#else
        UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
        UnityPrint(UnityStrPass);
        UNITY_PRINT_EOL;            
#endif
    }
    else
    {
        UNITY_PRINT_EOL;
        Unity.TestFailures++;
    }

    Unity.CurrentTestFailed = 0;
    Unity.CurrentTestIgnored = 0;
}

我还添加了 UNITY_PRINT_EOL;在UnityTestResultsBegin和 UnityEnd 的开头(已经有一个,我添加了另一个)。

这就是诀窍+它在每条消息之间放置了一个空格,以使所有内容都更具可读性。

于 2015-06-11T22:53:50.123 回答