您现在的位置是:亿华云 > IT科技类资讯
ABAP和Java SpringBoot的单元测试
亿华云2025-10-09 14:03:01【IT科技类资讯】9人已围观
简介ABAP 在ABAP类里,本地类(Local Class)里用关键字FOR TESTING声明过的方法, 在单元测试启动后会自动被调用到。
ABAP
在ABAP类里,的单元本地类(Local Class)里用关键字FOR TESTING声明过的测试方法,
在单元测试启动后会自动被调用到。
Spring Boot
在Spring及Spring Boot “Convention over configuration”的测试设定思路里,放在路径src/test/java下面以Tests.java结尾的的b2b信息网单元Java类会被当成单元测试类处理。
对上述项目执行命令行mvn clean install后,报错误消息:
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration,的单元 you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test at org.springframework.util.Assert.state(Assert.java:70) at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.getOrFindConfigurationClasses(SpringBootTestContextBootstrapper.java:202) at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.processMergedContextConfiguration(SpringBootTestContextBootstrapper.java:137) at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:409) at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildDefaultMergedContextConfiguration(AbstractTestContextBootstrapper.java:323) at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:277) at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildTestContext(AbstractTestContextBootstrapper.java:112) at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.buildTestContext(SpringBootTestContextBootstrapper.java:82) at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:120) at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:105) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:152) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:143) at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104) at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283) at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128) at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)从调用栈能看出,Spring Boot单元测试框架试图自动找到一个被施加单元测试的测试Java类,但是的亿华云单元失败了,所以报了异常。测试
由于我这个SpringBoot项目的入口是com.sap.smartService.SmartServiceApplication, 因此我需要在单元测试启动类里指定这个入口类:
@SpringBootTest(classes = com.sap.smartService.SmartServiceApplication.class)加上之后maven build成功:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
测试很赞哦!(224)
相关文章
- 3、不明先知,根据相关征兆预测可能发生的事件,以便提前做好准备,赶紧注册相关域名。;不差钱域名;buchaqian抢先注册,就是这种敏感类型。预言是最敏感的状态。其次,你应该有眼力。所谓眼力,就是善于从社会上时不时出现的各种热点事件中获取与事件相关的域名资源。眼力的前提是对域名领域的熟悉和丰富的知识。
- 永远不要在代码中使用“User”这个词!
- 浅析Python装饰器中的@property
- Python 下载大文件,哪种方式速度更快!
- 什么是im域名?新手需要了解im域名哪些?
- 一个U盘装N款系统不是梦!超级好用的装机神器来了!
- DevOps 专业人士爱用的 25 种编程语言:Typescript 最受欢迎
- 一天一夜,写完了这份高效组织 Npm Script 优秀实践
- 4、域名传输时,取决于域名原始用户的邮箱是否有效,以及他是否将密码发送到此邮箱。
- 一篇文章带你了解CSS定位知识