ScalaTest - Java与Scala测试


Apache
跨平台
Scala

软件简介

Scala Test 是一个开源测试框架。ScalaTest旨在令测试更加高效。其开发者Bill
Venners(Artima主编,同时也是资深的程序员)这样描述到:

“ScalaTest
1.0是比JUnit和TestNG更加高阶的测试编写工具,这个Scala应用在JVM上运行,可以测试Scala以及Java代码。除了与JUnit
TestNG的深层集成,同时还支持Ant任务,与maven集成,并包括了流行的Java
mocking框架JMockEasyMock以及Mockito的语法增强。通过JUnit集成,ScalaTest可以轻松地在Eclipse
NetBeans以及IntelliJ
IDEA
等IDE,以及Infinitest等生产工具中使用。

测试代码:

import org.scalatest.FlatSpec  
import org.scalatest.matchers.ShouldMatchers

class StackSpec extends FlatSpec with ShouldMatchers {

  "A Stack" should "pop values in last-in-first-out order" in {  
    val stack = new Stack[Int]  
    stack.push(1)  
    stack.push(2)  
    stack.pop() should equal (2)  
    stack.pop() should equal (1)  
  }

  it should "throw NoSuchElementException if an empty stack is popped" in {  
    val emptyStack = new Stack[String]  
    evaluating { emptyStack.pop() } should produce [NoSuchElementException]  
  }  
}

在线API文档:http://www.ostools.net/apidocs/apidoc?api=scalatest-1.7.2