简体   繁体   中英

Failure trace window for junit 3 doesn't show expected values

I'm executing some JUnit test cases with the Android SDK, and I've found that none of the assertEquals are showing their expected values in the log.

Here is an example assertion.

assertEquals("mocks", model.getUseTable());

Here is the failure exception.

junit.framework.ComparisonFailure: expected:<...k...> but was:<......>
at ca.thinkingmedia.gems.test.models.AbstractModelTest.test_Auto_Table_Name(AbstractModelTest.java:17)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:545)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1575)

As you can see the expected values are masked with dots. This is making it very time consuming to figure out what wrong values were checked.

Is there a way to have these values shown correctly in the exception messages?

You can do

final String actual = model.getUseTable()
assertEquals("Expecting mocks but was " + actual, "mocks", actual);

and the message will be in the log.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM