我正在处理一个相当小的项目(就依赖关系而言),每当我运行单元测试时,JVM需要8秒才能加载,然后才能在0.2s中运行实际测试。
我的环境:
我担心我的环境中一定有什么东西会让我花这么长时间,我希望以前有人见过这个问题,找到了问题的根源,也许是一个解决方案?
如果我的PATH环境变量真的很长,那有关系吗?
当我运行JUnit测试时会发生什么?
我想要运行的实际测试是:
public class TemplateLocationCalculatorTest {
private TemplateLocationCalculator target = new TemplateLocationCalculator();
@Test
public void whenGivenRootReturnIndex(){
Assert.assertEquals("index", target.calculate("/"));
}
}目标类是:
public class TemplateLocationCalculator {
public String calculate(String string) {
return "index";
}
}我希望你会同意我的意见,当我说这不应该花很长的时间来装载。
发布于 2017-02-19 10:10:01
在这里行动。
在使用了聊天中提出的建议之后,我使用了Microsoft进程监视器,在进行了大量的过滤之后,我发现AV软件Avecto DefendPoint正在我的机器上运行,这似乎是瓶颈。每当我开始测试时,它的运行速度大约是25%,在我看来,这似乎表明它在我的四个核心之一的一个线程上以全速运行。我不是这台机器的管理员,所以我无法禁用它来验证这一假设,但通常情况下,如果其他人应该看到这个问题,检查它是否可能是您的反病毒软件。
发布于 2017-01-30 06:43:07
一个潜在的原因可以是组件扫描和自动装配在启动过程中.您可以通过为测试创建一个单独的config文件来限制这一点,该文件限制了这里解释的组件搜索空间。
在配置中,可以使用懒惰负载bean <beans default-lazy-init="true">或显式连接bean(详见这里)。
<beans ...>
<!-- this bean will be injected into the OrderServiceTest class -->
<bean id="target" class="TemplateLocationCalculator" />
<!-- other beans -->
</beans>然后在test类中,我们指定了新的配置文件:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/path/to/test-config.xml" })
public class TemplateLocationCalculatorTest {
@Autowired
private TemplateLocationCalculator target;
@Test
public void whenGivenRootReturnIndex(){
Assert.assertEquals("index", target.calculate("/"));
}
}
@Bean
public class TemplateLocationCalculator {
public String calculate(String string) {
return "index";
}
}https://stackoverflow.com/questions/41721378
复制相似问题