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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:38:10+00:00 2026-06-13T13:38:10+00:00

I have the following junit tests in an UTF-8 encoded file. public class EncodingTest

  • 0

I have the following junit tests in an UTF-8 encoded file.

public class EncodingTest {

 private static byte[] utf8Bytes;

 private static byte[] utf8Bytes2;

 private static byte[] utf8Bytes3;

 static {
try {
    utf8Bytes = "åæø".getBytes("UTF-8");
    utf8Bytes2 = new byte[] { (byte) 0xc3, (byte) 0xa5, (byte) 0xc3, (byte) 0xa6, (byte) 0xc3, (byte) 0xb8 };
    utf8Bytes3 = "\u00E5\u00E6\u00F8".getBytes("UTF-8");
} catch (final UnsupportedEncodingException e) {
    assertTrue(false);
}

 }

 @Test
 public void testUTF8Encoding1() throws UnsupportedEncodingException {
assertTrue(Arrays.equals(utf8Bytes, utf8Bytes2));
 }

 @Test
 public void testUTF8Encoding2() throws UnsupportedEncodingException {
 assertTrue(Arrays.equals(utf8Bytes2, utf8Bytes3));
 }

 @Test
 public void testUTF8Encoding3() throws UnsupportedEncodingException {
 assertEquals(new String(utf8Bytes), new String(utf8Bytes2));
 }

 @Test
 public void testUTF8Encoding4() throws UnsupportedEncodingException {
 assertEquals(new String(utf8Bytes2), new String(utf8Bytes3));
 }
}

The test fails in ant but works in eclipse. The ANT task I’m using it the following:

<target
    name="test"
    depends="compile-tests"
    description="Test the full company tests" >

    <junit fork="yes" haltonfailure="yes" >
        <jvmarg value="-Dfile.encoding=UTF-8"/>
        <classpath>

            <path refid="test.classpath" />

            <fileset dir="war/WEB-INF/lib/" >

                <include name="*.jar" />
            </fileset>
        </classpath>

        <formatter
            type="plain"
            usefile="false" />
        <!-- to screen -->
        <!-- formatter type="plain" / -->
        <!-- to file -->

        <batchtest>

            <fileset
                dir="test/classes/"
                includes="**/*Test.class" />
        </batchtest>
    </junit>
</target>

The output is the following:

test:
[junit] Testsuite: com.company.appengine.EncodingTest
[junit] Tests run: 4, Failures: 2, Errors: 0, Time elapsed: 0,028 sec
[junit]
[junit] Testcase: testUTF8Encoding1 took 0,004 sec
[junit]     FAILED
[junit]
[junit] junit.framework.AssertionFailedError:
[junit]     at com.company.appengine.EncodingTest.testUTF8Encoding1(EncodingTest.java:42)
[junit]
[junit] Testcase: testUTF8Encoding2 took 0 sec
[junit] Testcase: testUTF8Encoding3 took 0,001 sec
[junit]     FAILED
[junit] expected:<[åæø]> but was:<[åæø]>
[junit] junit.framework.AssertionFailedError: expected:<[åæø]> but was:<[åæø]>
[junit]     at com.company.appengine.EncodingTest.testUTF8Encoding3(EncodingTest.java:52)
[junit]
[junit] Testcase: testUTF8Encoding4 took 0 sec

Any idea?

  • 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-13T13:38:11+00:00Added an answer on June 13, 2026 at 1:38 pm

    Please first make sure that javac knows that your source file is encoded in utf-8. If you compile using javac task, supply encoding attribute.

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

Sidebar

Related Questions

I am new to junit testing and I have the following test - public
I have a property file with the following junit.version=3.8.1 dbcp.version=5.5.27 oracle.jdbc.version=10.2.0.2.0 I try to
I have following plist: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
I have a number of tests failing in the following JUnit Task. <target name=test-main
I have following class: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={classpath:/com/home/app/Home-ctx.xml}) public class LoginDetailsTest { public static void main(String[]
I have the following build.xml file setup in phpUnderControl. <target name=phpunit> <exec executable=phpunit dir=${basedir}/httpdocs
I have Eclipse plug-in and junit tests for it, which are using jMock library.
I have an Ant file contains a Junit target, before running the Junit target
I have the following tasks in ant: <target name=init-junit depends=init> <mkdir dir=${junit.reports.individual} /> <property
I have a number of JUnit tests in my project that test my DataStore

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.