2016-04-13 34 views
2

Bir Java projesini test etmek için ScalaTest kullanmaya çalışıyorum. Testi yazdım ve işe yaradı (çünkü bunları IntelliJ içinde başarıyla çalıştırdığım için biliyorum), ancak tutulması için çalışmam gerekiyor.ScalaTest eklentisi eclipse sınıfımda bulamıyor

İşte benim kodu (testin içini çok önemli olmamalı) 'dir:

@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() 

    } 

    } 

} 

denedim Ne:

  • Menü Run > Run As...: Geçerli hiçbir seçenek vardır.
  • Yeni bir "ScalaTest" yapılandırması oluşturun. Ancak "Suite Sınıfı" nı seçmek istediğimde hiçbir sınıf bulunamadı.
  • @RunWith (classOf [JUnitRunner]) sınıfımın üzerine yerleştirin. Sonra Menu Run > Run As... > Junit Test yapabilirim. Ama "JUnit Testi bulunamadı" diyen bir hata alıyorum.

Ancak, ben sağ, Projemde tıklayarak bir Scala tercüman oluşturmak ve çalışacaktır (ama IDE junit görünümü kullanmaz ve her değişiklikten sonra elle yeniden derlemek için beni zorlar, hangi (new PlacingOrderSpec()).execute() yazabilirsiniz.

ben eksik? sonunda JUnit ile benim testler başardım

cevap

0

.

sorun aldığımızda dosyama üstündeki eksik package beyanı. ve @RunWith açıklama, ben oldu J ile testleri çalıştırabilme Birimi. Yine de ScalaTest eklentisi ile çalışmıyor, ancak benim durumum için sorun değil.

Diğer yanıtlar ScalaTest eklentisi sorununa hoş geldiniz.