为 junit spring boot 应用程序编写负载测试

writing load tests for junit springboot application

我写了下面的junit测试

@SpringBootTest
public class abc {

@Autowired
private ActorService actorService;

@Test
@Transactional
public void testCorrectIdHandlingForNewInsertedActors() {
    int elementsInDb = 0;
    for (Actor a : this.actorService.findAll()) {
        elementsInDb++;
    }

    Actor actor = this.actorService.saveAndSetId(new Actor());

    assertEquals(elementsInDb + 1, actor.getId());
}
}

现在我想为性能测试编写一些负载测试,但我不知道在我的 spring 应用程序中可以使用哪些工具。我正在使用 gradle 作为我的构建工具。任何教程将不胜感激。

PS: 我已经尝试过 zerocode 但对我不起作用

您有一些开箱即用的有用功能,例如 @RepeatedTest@Timeout (请参阅 JUnit 5 注释参考 here这分别允许您重复特定的测试方法 n 次并设置测试自动失败前的最大时间限制。

除此之外,为了更完整和有意义的负载测试,您应该考虑依赖成熟的解决方案,例如 Apache JMeter or Gatling,而不是单元测试。