Java eclipse中的ScalaTest插件找不到我的类
我正在尝试使用ScalaTest测试一个Java项目。我已经编写了测试,并且它可以工作(我知道这一点,因为我已经在IntelliJ中成功地运行了它们),但是我还没有在eclipse中使它工作 下面是我的代码(测试的内部不应该太重要):Java eclipse中的ScalaTest插件找不到我的类,java,eclipse,scala,junit4,scalatest,Java,Eclipse,Scala,Junit4,Scalatest,我正在尝试使用ScalaTest测试一个Java项目。我已经编写了测试,并且它可以工作(我知道这一点,因为我已经在IntelliJ中成功地运行了它们),但是我还没有在eclipse中使它工作 下面是我的代码(测试的内部不应该太重要): @ContextConfiguration( classes=数组(classOf[OrderApplicationSpecContext]), loader=classOf[SpringApplicationContextLoader]) 类PlacingOrd
@ContextConfiguration(
classes=数组(classOf[OrderApplicationSpecContext]),
loader=classOf[SpringApplicationContextLoader])
类PlacingOrderSpec使用org.scalatest.Matchers扩展path.FunSpec{
@自动连线val orderApplication:orderApplication=null
@自动连线val customerRepository:customerRepository=null
@自动连线val orderRepository:orderRepository=null
@自动连线val creditCardService:creditCardService=null
新建TestContextManager(this.getClass).prepareTestInstance(this)
描述(“下订单”){
描述(“与现有客户一起”){
val客户=新客户()
customerRepository.save(客户)
它(“应返回有效的订单ID”){
val orderId=orderApplication.placeOrder(123L,customer.getTid,“123”)
orderId不应为空
}
描述(“当信用卡未用完且未过期时”){
Mockito.when(creditCardService.isMaxedOut(“123”,1.23))。然后返回(false)
Mockito.when(creditCardService.expirationDate(“123”))。然后返回(LocalDate.MAX)
它(“应创建状态为的订单”){
val orderId=orderApplication.placeOrder(123L,customer.getTid,“123”)
val orderStatus=orderApplication.getOrderStatus(orderId)
订单状态应为(“进行中”)
}
它(“应创建可从客户处访问的订单”){
val orderId=orderApplication.placeOrder(123L,customer.getTid,“123”)
val orders=orderApplication.findOrdersForCustomer(customer.getId)
订单不应该是空的
检查员。准确地说(1,订单){
_.getId应为(orderId)
}
}
}
描述(“信用卡用完时”){
Mockito.when(creditCardService.isMaxedOut(“123”,1.23))。然后返回(true)
它(“应创建状态为的订单”){
val orderId=orderApplication.placeOrder(123L,customer.getTid,“123”)
val orderStatus=orderApplication.getOrderStatus(orderId)
订单状态应为(“付款失败”)
}
它(“应该创建一个客户无法访问的订单”){
val orderId=orderApplication.placeOrder(123L,customer.getTid,“123”)
val orders=orderApplication.findOrdersForCustomer(customer.getId)
检查员。所有(订单){
_.getId不应为(orderId)
}
}
}
描述(“信用卡到期时”){
Mockito.when(creditCardService.isMaxedOut(“123”,1.23))。然后返回(false)
Mockito.when(creditCardService.expirationDate(“123”))。然后返回(LocalDate.now().plusMonths(1))
它(“应创建状态为的订单”){
val orderId=orderApplication.placeOrder(123L,customer.getTid,“123”)
val orderStatus=orderApplication.getOrderStatus(orderId)
订单状态应为(“付款失败”)
}
它(“应该创建一个客户无法访问的订单”){
val orderId=orderApplication.placeOrder(123L,customer.getTid,“123”)
val orders=orderApplication.findOrdersForCustomer(customer.getId)
检查员。所有(订单){
_.getId不应为(orderId)
}
}
}
customerRepository.deleteAll()
}
}
}
我所尝试的:
- 菜单
:没有适用的选项Run>runas…
- 创建一个新的“ScalaTest”配置。但当我想选择我的“套件类”时,找不到任何类
- 将@RunWith(classOf[JUnitRunner])放在我的类的顶部。然后我可以做
。但是我得到一个错误,说“没有找到JUnit测试”李>Menu Run>runas…>Junit测试
(new PlacingOrderSpec()).execute()
,这将起作用(但不会使用IDE的junit视图,并强制我在每次更改后手动重新编译)
我错过了什么?我终于成功地用JUnit运行了测试 问题是我的文件顶部缺少
package
语句。有了它和@RunWith
注释,我可以用JUnit运行测试。但是,它仍然不能与ScalaTest插件一起工作,但这对我来说没问题
对于ScalaTest插件问题,欢迎提供其他答案
@ContextConfiguration(
classes = Array(classOf[OrderApplicationSpecContext]),
loader = classOf[SpringApplicationContextLoader])
class PlacingOrderSpec extends path.FunSpec with org.scalatest.Matchers {
@Autowired val orderApplication: OrderApplication = null
@Autowired val customerRepository: CustomerRepository = null
@Autowired val orderRepository: OrderRepository = null
@Autowired val creditCardService: CreditCardService = null
new TestContextManager(this.getClass).prepareTestInstance(this)
describe("Placing an Order") {
describe("With an existing customer") {
val customer = new Customer()
customerRepository.save(customer)
it("should return a valid order ID") {
val orderId = orderApplication.placeOrder(123L, customer.getTid, "123")
orderId should not be null
}
describe("When the credit card is not maxed out and not expired") {
Mockito.when(creditCardService.isMaxedOut("123", 1.23)).thenReturn(false)
Mockito.when(creditCardService.expirationDate("123")).thenReturn(LocalDate.MAX)
it("Should create an order with status <IN PROGRESS>") {
val orderId = orderApplication.placeOrder(123L, customer.getTid, "123")
val orderStatus = orderApplication.getOrderStatus(orderId)
orderStatus should be("IN PROGRESS")
}
it("Should create an order accessible from the customer") {
val orderId = orderApplication.placeOrder(123L, customer.getTid, "123")
val orders = orderApplication.findOrdersForCustomer(customer.getTid)
orders should not be empty
Inspectors.forExactly(1, orders) {
_.getTid should be (orderId)
}
}
}
describe("When the credit card is maxed out") {
Mockito.when(creditCardService.isMaxedOut("123", 1.23)).thenReturn(true)
it("Should create an order with status <PAYMENT FAILED>") {
val orderId = orderApplication.placeOrder(123L, customer.getTid, "123")
val orderStatus = orderApplication.getOrderStatus(orderId)
orderStatus should be("PAYMENT FAILED")
}
it("Should create an order not accessible from the customer") {
val orderId = orderApplication.placeOrder(123L, customer.getTid, "123")
val orders = orderApplication.findOrdersForCustomer(customer.getTid)
Inspectors.forAll(orders) {
_.getTid should not be(orderId)
}
}
}
describe("When the credit card is expired") {
Mockito.when(creditCardService.isMaxedOut("123", 1.23)).thenReturn(false)
Mockito.when(creditCardService.expirationDate("123")).thenReturn(LocalDate.now().plusMonths(1))
it("Should create an order with status <PAYMENT FAILED>") {
val orderId = orderApplication.placeOrder(123L, customer.getTid, "123")
val orderStatus = orderApplication.getOrderStatus(orderId)
orderStatus should be("PAYMENT FAILED")
}
it("Should create an order not accessible from the customer") {
val orderId = orderApplication.placeOrder(123L, customer.getTid, "123")
val orders = orderApplication.findOrdersForCustomer(customer.getTid)
Inspectors.forAll(orders) {
_.getTid should not be(orderId)
}
}
}
customerRepository.deleteAll()
}
}
}