如何使用Scala(Test)进行检查实例
我正在尝试将ScalaTest合并到我的Java项目中;将所有 JUnit 测试替换为 ScalaTests。在某一时刻,我想检查Guice的注入器是否注入了正确的类型。在Java中,我有一个这样的测试:
public class InjectorBehaviour {
@Test
public void shouldInjectCorrectTypes() {
Injector injector = Guice.createInjector(new ModuleImpl());
House house = injector.getInstance(House.class);
assertTrue(house.door() instanceof WoodenDoor);
assertTrue(house.window() instanceof BambooWindow);
assertTrue(house.roof() instanceof SlateRoof);
}
}
但是我在ScalaTest上做同样的事情时遇到了一个问题:
class InjectorSpec extends Spec {
describe("An injector") {
it("should inject the correct types") {
val injector = Guice.createInjector(new ModuleImpl)
val house = injector.getInstance(classOf[House])
assert(house.door instanceof WoodenDoor)
assert(house.window instanceof BambooWindow)
assert(house.roof instanceof SlateRoof)
}
}
}
它抱怨该值不是 // 的成员。我不能在Scala中使用这种方式吗?instanceof
Door
Window
Roof
instanceof