且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spring Boot,测试主应用程序类

更新时间:2022-06-10 05:52:41

如果您使用的是 Spring initializr ,将为您创建该测试.您可以将其称为集成测试,因为它会尝试启动您的应用程序上下文(因此将所有类集成在一起).它是这样的:

If you are using Spring initializr, this test will be created for you. You may call it an integration test because it will try to start your application context (thus integrating all classes inisde it). It goes something like this:

@RunWith(SpringRunner.class)
@SpringBootTest
public class BootApplicationTests {

    @Test
    public void contextLoads() {
    // some more optional integration assertions here
    // like asserting number of beans, are they null, etc...
    }
}

对于您的特定域逻辑,您可以尝试断言是否创建了列表,但我会将其作为单元测试放在单独的类中.

And for your specific domain logic, you can try to assert if the list is created but I would put that in a separate class as a unit test.