3

一部のフィクスチャ データに REST サービスを利用する必要がある FlatSpec テスト クラスがあります。すべてのテストを一度に実行する場合、REST クライアントのインスタンス化は非常にコストがかかる可能性があるため、実際には 1 回だけにしたいと考えています。IDE で実行しているときに、1 つのテスト クラスだけを実行するためにも機能させることができますか?

4

2 に答える 2

0

Pawel の最後のコメントはよく合います。Suite の代わりに BeforaAndAfterAll を使用して Suite から継承した方が簡単でした。

import com.typesafe.config.ConfigFactory
import com.google.inject.Guice
import org.scalatest.{BeforeAndAfterAll, Suite}
import net.codingwell.scalaguice.InjectorExtensions.ScalaInjector

class EndToEndSuite extends Suite with BeforeAndAfterAll {

    private val injector = {
        val config = ConfigFactory.load
        val module = new AppModule(config) // your module here
        new ScalaInjector(Guice.createInjector(module))
    }

    override def afterAll {
        // your shutdown if needed
    }

    override val nestedSuites = collection.immutable.IndexedSeq(
        injector.instance[YourTest1],
        injector.instance[YourTest2] //...
    )
}
于 2015-06-25T09:12:33.377 に答える