且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将ScalaTest与Spring集成

更新时间:2022-01-14 10:01:11

使用TestContextManager,因为这会缓存上下文,这样就不会在每次测试时都重新构建它们.它是通过类注释配置的.

Use the TestContextManager, as this caches the contexts so that they aren't rebuilt every test. It is configured from the class annotations.

@ContextConfiguration(
  locations = Array("myPackage.UnitTestSpringConfiguration"), 
  loader = classOf[AnnotationConfigContextLoader])
class AdminLoginFeatureTest extends FeatureSpec with GivenWhenThen with ShouldMatchers {

  @Autowired val app: WebApplication = null
  @Autowired val siteDAO: SiteDAO = null
  new TestContextManager(this.getClass()).prepareTestInstance(this)

  feature("Admin Login") {
    scenario("Correct username and password") {...}
  }
}