简体   繁体   中英

Junit test failing in a Jenkins Gradle build but not locally

I have a weird situation with Jenkins... We've just started using Gradle for a project at my job and when I run the tests locally with JUnit everything is fine. But when these tests are run by jenkins for the builds of branch "A", only one test fails because of an assert(always the same test).

org.junit.ComparisonFailure: expected: "E[ZZ0530]Z" but was:"E[SY5654]Z"

It looks like the mock is not injected or the mock is ignoring the "when" mocking statement.

Here is the test :

@Test
public void testEvent() {
    Date eventDateTime = TimeUtils.parseDate("2013-05-30 00:00:00");
    event.setEventDatetime(eventDateTime);

    //Mocking the prefix return 
    Mockito.when(eventCodeHelperMock.getEventCodePrefixFromEvent(event)).thenReturn("EZZ");

    //Tested methode
    eventWrapper.setSuffix("Z");

    // Event code = prefix + date + suffix
    assertEquals("EZZ0530Z", event.getEventCode());
}

What is a lot stranger is that when I create a branch "B" from branch "A" all the tests succeeds when the build is created on jenkins.

I've made some research and tried to force an other build, wipe out the current workspace and recreating the job but it didn't work.

Thanks for your help!

I have had similar problems in the past and it has been due to the order in which the junits tests are run. For example, one test modifies the state of an object but you dont see the effects of this till the tests run in a different order, and tests unexpectedly fail. There is not sufficient code in the question you have posted to tell whether this is definitely the case, but I would recommend checking the order in which the tests are being run, and also look at the objects that you are using to determine if there is a problem with the state of those objects being 'dirtied'.

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