是否可以使用Maven使用junit 5运行Spring Boot测试?我正在使用Spring Boot 2.0.0.M3,junit 5.0.0-M6,maven 3.5.0。其他junit5测试(没有spring上下文)也可以工作。
有一个简单的控制器:
@Controller
public class HomeController {
@GetMapping("/")
String home() {
return "home";
}
}
Run Code Online (Sandbox Code Playgroud)
并测试:
@ExtendWith(SpringExtension.class)
@WebMvcTest(HomeController.class)
@Import(SecurityConfig.class)
class HomeControllerTest {
@Autowired
private MockMvc mvc;
@Test
void shouldReturnHomeTemplate() throws Exception {
this.mvc.perform(get("/").accept(MediaType.TEXT_HTML))
.andExpect(status().isOk())
.andExpect(content().string(startsWith("<!DOCTYPE html>")));
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用intellij运行它时,一切正常,但是maven构建以失败告终:
[警告]分叉的JVM 1中的stdin流损坏。请参见转储文件somePath / target / surefire-reports / 2017-07-28T13-50-15_071-jvmRun1.dumpstream
--debug标志显示:
java.lang.OutOfMemoryError:Java堆空间
在内部,2017-07-28T13-50-15_071-jvmRun1.dumpstream我可以找到约100个相同的异常(每个spring log一个)
分叉的JVM 1中损坏的stdin流。Stream'13:50:15.914 [main]调试org.springframework.test.context.BootstrapUtils-从类[org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]实例化CacheAwareContextLoaderDelegate。java.lang.IllegalArgumentException:流标准输入已损坏。命令'第三个字符后的预期逗号'13:50:15.914 [main]调试org.springframework.test.context.BootstrapUtils-从类[org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]实例化CacheAwareContextLoaderDelegate。在org.apache.maven.plugin的org.apache.maven.plugin.surefire.booterclient.output.ForkClient $ OperationalData。(ForkClient.java:469)处。
Maven surefire插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M6</version>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud) 如何在新进程中读取stdin?我可以把线和打印只在主过程中.我应该传递给get_line控制台设备还是类似的或者不可能?
我的代码:
-module(inputTest).
-compile([export_all]).
run() ->
Message = io:get_line("[New process] Put sth: "),
io:format("[New process] data: ~p~n", [Message]).
main() ->
Message = io:get_line("[Main] Put sth: "),
io:format("[Main] data: ~p~n", [Message]),
spawn(?MODULE, run, []).
Run Code Online (Sandbox Code Playgroud)