Search code examples
javaseleniumgradleassertj

AssertJ wrong failure when comparing two Unicode strings


I switched from TestNG assertions to Assertj, I really like the immense flexibility I get. However, I get a bunch of failures now when running some Selenium tests. I am checking some page titles and some anchor texts like this:

assertThat(page.getTitle()).isEqualTo("This® is one annoying title");

This is always failing do to the special character. Even weirder, it does not fail when running the test as jUnit test in Eclipse, but it always fails when running the tests with gradle, from command line, in Windows. Am I missing something?


Solution

  • My bad, it seems gradle needs to be configured for UTF-8 when needed. Here's the fix, in build.gradle file:

    apply plugin: 'java'
    compileJava.options.encoding = 'UTF-8'
    tasks.withType(JavaCompile) {
        options.encoding = 'UTF-8'
    }