2013-05-22 3 views
2

메인 메소드가 실행될 때 웹 서버가 시작되어 일부 RESTful 서비스 (Dropwizard 사용)를 호스트하는 애플리케이션이 있습니다. HTTP 메서드 (Java 메서드 대신)에 액세스하는 테스트를 작성하려고하므로 테스트에는 서버가 실행되고 있다는 전제 조건이 있습니다.Gradle에서 테스트를 실행하기 전에 별도의 스레드에서 java 프로그램을 실행하십시오.

task run (dependsOn: 'classes', type: JavaExec) { 
    main = 'com.some.package.to.SomeService' 
    classpath = sourceSets.main.runtimeClasspath 
    args 'server', 'some.yml' 
} 

서버도 시작하는 데 몇 초 정도 걸립니다 :

다음은 웹 서버 응용 프로그램을 실행하고 시작하는 내 작업입니다. 대략, 제가하고 싶은 것은이 같은 것입니다 : 즉

test.doFirst { 
    println "Starting application..." 
    Thread.startDaemon { 
     // What goes here??? 
    } 
    sleep 20000 
    println "Application should be started." 
} 

, 테스트를 실행하기 전에, 별도의 스레드에서 응용 프로그램을 시작하고, 테스트를 실행 그것을 시작 완료 시간을주기 전에 약간의 시간을 기다립니다.

즉, Thread.startDaemon (tasks.run.execute()이 작동하지 않음)이 무엇인지 알 수 없으며, 이것이 최선의 방법이라해도 말입니다. 이것에 대해 가장 좋은 방법은 무엇입니까?

감사합니다. Gradle을 목표를 호출 할 때

task startServer (type: Exec) { 
    workingDir 'tomcat/bin' 
    // using START hopefully forks the process 
    commandLine 'START', 'start.bat' 
    standardOutput = new ByteArrayOutputStream() 
    ext.output = { 
     return standardOutput.toString() 
    } 
    // loop through output stream for finished flag 
    // or just put a timeout here 
} 

task testIt (type: Test) { 
    description "To test it." 
    include 'org/foo/Test*.*' 
} 

그런 다음, "gradle.bat startserver는 testIt"를 호출

답변

1

내가 할 아마 것 이것이 같은 것입니다. 이것이 기본 아이디어입니다.

관련 문제