2016-08-16 50 views
1

我使用Spray框架編寫了一個小型Web服務。我可以使用sbt run運行它,然後在瀏覽器中進行測試。從SBT執行Gatling負載測試

現在我寫了一個使用Gatling框架的負載測試。

package com.abhi 

import io.gatling.core.Predef._ 
import io.gatling.http.Predef._ 
import scala.concurrent.duration._ 

class LoadTest extends Simulation { 
    val httpConf = http 
     .baseURL("http://localhost:8999") 
     .acceptHeader("application/json") 
     .doNotTrackHeader("1") 
     .acceptLanguageHeader("en-US,en;q=0.5") 
     .acceptEncodingHeader("gzip, deflate") 
     .userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0") 

    val scn = scenario("BasicSimulation") 
     .exec(http("request_1") 
     .get("/path1")) 
     .pause(5) 

    setUp(
     scn.inject(atOnceUsers(10)) 
    ).protocols(httpConf) 
} 

測試位於夾src/test/scala-2.11和噴碼是src/main/scala-2.11

當我運行sbt test它只是打印成功沒有任何運行我的Web服務器或運行上述定義的測試。它只是在3秒內打印成功並出去。

我怎樣才能

  1. 確保當我做了sbt test噴霧web應用 開始
  2. 的galing負載測試運行鍼對啓動服務器

編輯:我還嘗試sbt test scenarios:BasicSimulation,它拋出錯誤

Not a valid key: BasicSimulation 
[error] scenarios:BasicSimulation 

回答

1

您必須使用Gatling sbt plugin才能從sbt觸發。請注意,它不以默認配​​置運行,但在the gatling onegatling:test中運行。

+0

謝謝!我配置了插件,我可以進行門控:測試,但它仍然不啓動噴霧服務器。我可以做一個「加油」:測試做一個「加油」嗎?如果我做了一個「運行gatling:測試」,它永遠不會跑出來,所以永遠不要跑到加特林:test –

+1

也許一位專家可以向你解釋如何做到這一點。然後,您可以運行2個不同的sbt進程。但是,從負載測試的角度來看,這沒有任何意義:您將在localhost和Gatling上進行測試,並且測試的應用程序將共享資源(CPU),因此您的結果將完全不相關。 –

+0

非常感謝你的幫助。我會用更具體的sbt標籤打開另一個問題。 –

0

加特林已經寫成Scala的應用 - 它就會開始按照一個標準的JVM的應用程序 - 你可以在startup script gatling.sh看到:

# Run Gatling 
java $JAVA_OPTS -cp "$GATLING_CLASSPATH" io.gatling.app.Gatling "[email protected]" 

SBT並不「知道」如何啓動加特林Simulation就像它「知道」如何運行Specs2 Specification一樣。幸運的是,似乎有一個Gatling SBT插件可用,它可以做正是你想要的 - 請查看demo project on GitHub