Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
478 views
in Technique[技术] by (71.8m points)

java - Comparing unicode characters in Junit

I had problems in some flow with unicode chars in some of my flows. So i fixed the flow and added a test.

assertEquals("Bj?rk", buyingOption.getArtist());

the buyingOption.getArtist() will return the same name that is on ,here is a snippet :

alt text

but junit will fail with the message :

junit.framework.ComparisonFailure: null 
Expected :Bj?rk
Actual   :Bj?rk
    at com.delver.update.system.AECSystemTest.basicOperationtsTest1(AECSystemTest.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is probably due to the default encoding used for your Java source files. The ? in the string literal in the JUnit source code is probably being converted to something else when the test is compiled.

To avoid this, use Unicode escapes (uxxxx) in the string literals in your JUnit source code:

assertEquals("Bju00F6rk", buyingOption.getArtist());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...