代码之家  ›  专栏  ›  技术社区  ›  Vikram

SpringBoot Rest应用程序+Arquillian

  •  2
  • Vikram  · 技术社区  · 8 年前

    我想测试我的Rest应用程序,该应用程序使用SpringBoot与Arquillian进行测试,但没有一个在线示例有效。我无法测试GET调用,并且在部署到Jboss EAP-6.4时面临困难。有谁能指导我如何实现这一点吗。有简单的例子吗???

    2 回复  |  直到 8 年前
        1
  •  1
  •   lordofthejars    8 年前

        2
  •  0
  •   Vikram    8 年前

    这个链接帮助我解决了这个问题: Adding all Maven dependencies to Arquillian .

    有效的代码:

    @Deployment
    public static Archive<?> createTestArchive() {
    
            File[] files = Maven.resolver()
                            .loadPomFromFile("pom.xml")
                            .importRuntimeDependencies()
                            .resolve().withTransitivity()
                            .asFile(); 
    
        return ShrinkWrap.create(WebArchive.class, "FileUploadIssue.war")
                         .addPackages(true,"com.example")
                         .addAsLibraries(files); 
    }
    
    
    @Test
    @RunAsClient
    public void shouldGetFileContents() {
    
        String result = restTemplate.getForObject(contextPath + "upload/sayhello", String.class);
    
        System.out.println( "Test : " + result);
    }