ABAP和Java SpringBoot的单元测试
ABAP
在ABAP类里,本地类(Local Class)里用关键字FOR TESTING声明过的方法,
在单元测试启动后会自动被调用到。
Spring Boot
在Spring及Spring Boot “Convention over configuration”的设定思路里,放在路径src/test/java下面以Tests.java结尾的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成功:
有朋友问遇到在安卓手机上安装Fiori Client,打开的时候提示需要安装证书,如下图所示:
我在自己的Android手机试了试,因为我没有装Fiori Client,所以就用手机浏览器直接访问https://go.sap.com:
弹出了类似的对话框。点击取消之后,可以手动输入用户名和密码,但是每次都这样,不太方便。
如何安装这个证书呢?
IE浏览器里,Tools->Internet Options->Content->Certificates:
选中合适的证书,点Export按钮导出:
选择export the private key:导出私匙:
这个pfx文件就是Android手机浏览器里需要的.pfx证书:
导出时设置一个密码,在手上上导入这个证书时,需要输入这个密码才能成功:
pfx证书导出到电脑上,如下图所示:
把这个证书拷贝到Android手机上,单击即可安装。安装时需要输入在电脑上导出时设置的密码。
输入密码后,自动显示证书内容并进行安装:
下次访问https://go.sap.com后,直接选择这个安装好的证书即可完成认证,不需要再手动输入用户名和密码了。
要获取更多Jerry的原创文章,请关注公众号"汪子熙"。
- 点赞
- 收藏
- 关注作者
评论(0)