繁体   English   中英

Spring Boot 单元测试静态文件解析器

[英]Spring Boot unit test static file parser

我有一个名为 config.json 的配置文件,我需要对配置文件是否存在进行单元测试并打印它的内容。 在 PHP 中,我使用配置解析器对其进行了测试,但 Spring Boot 没有配置解析器,因此我不确定在 Spring Boot 中测试编写相同内容的最佳方法是什么。

$config = new ConfigParser();
$file = $config->findConfigurationFile('config.json');

echo $file;

如果您只需要验证文件是否存在,您可以使用 java File API:

import static org.junit.Assert.*;
public class ConfigurationTests {

  public void ConfigFileShouldExist() throws Exception{
    assertEquals(new File("config.json").exists(), true);
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM