使用openclover时单元测试失败

时间:2017-12-11 12:23:23

标签: spring-boot apache-camel maven-3 junit4 clover

我目前正在为我继承的项目添加单元测试。当我这样做时,单元测试运行良好并成功通过:

mvn clover:clean clover:instrument clover:aggregate clover:clover

我收到以下内容:

[ERROR] Errors:
[ERROR]   RequestFileRouteTest.successFilePresent:48->__CLR4_2_1hpqk65cb:57 » NoSuchFile

测试用例非常简单:

package b.pi.ac.md.file.outward;

import b.pi.ac.md.config.SourceConfiguration;
import com.github.stefanbirkner.fakesftpserver.rule.FakeSftpServerRule;
import java.io.IOException;
import java.nio.charset.Charset;
import lombok.extern.slf4j.Slf4j;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.test.spring.CamelSpringBootRunner;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

@RunWith(CamelSpringBootRunner.class)
@SpringBootTest
@ActiveProfiles("test")
@Slf4j
public class RequestFileRouteTest {

    private static final String TEST_FILE_NAME = "test.txt";

    @Rule
    public final FakeSftpServerRule sftpd = new FakeSftpServerRule();

    @Autowired
    private CamelContext context;

    @Autowired
    private SourceConfiguration.Camel camelConfig;
    @Autowired
    private SourceConfiguration.Dynamo dynamoConfig;

    @Before
    public void init() throws Exception {
        sftpd.createDirectories(String.format("/%s/%s", dynamoConfig.getSftpUserName(),
                camelConfig.getRemoteFileDestination()));
    }

    @Test
    public void successFilePresent() throws IOException {
        NotifyBuilder notification = new NotifyBuilder(context)
                .from(String.format("file:%s", camelConfig.getFileDestination()))
                .whenDone(1)
                .create();

        notification.matchesMockWaitTime();

        assertTrue(sftpd.existsFile(String.format("/%s/%s", camelConfig.getRemoteFileDestination(), TEST_FILE_NAME)));
        assertEquals("test content", sftpd.getFileContent(
                String.format("/%s/%s", camelConfig.getRemoteFileDestination(), TEST_FILE_NAME),
                Charset.forName("UTF-8")));

    }
}

我有另一个使用的测试用例:

  • spring boot 1.5.9
  • camel 2.20.1

它与三叶草成功运行。

我正在跑步:

  • openclover 4.2.1
  • maven 3.5.2
  • Java 8 update 152
  • Macos High Sierra

非常感谢任何见解

0 个答案:

没有答案