core-scala: initial commit
This commit is contained in:
17
core-scala/src/test/scala/samples/junit.scala
Normal file
17
core-scala/src/test/scala/samples/junit.scala
Normal file
@@ -0,0 +1,17 @@
|
||||
package samples
|
||||
|
||||
import org.junit._
|
||||
import Assert._
|
||||
|
||||
@Test
|
||||
class AppTest {
|
||||
|
||||
@Test
|
||||
def testOK() = assertTrue(true)
|
||||
|
||||
// @Test
|
||||
// def testKO() = assertTrue(false)
|
||||
|
||||
}
|
||||
|
||||
|
||||
108
core-scala/src/test/scala/samples/scalatest.scala
Normal file
108
core-scala/src/test/scala/samples/scalatest.scala
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright 2001-2009 Artima, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package samples
|
||||
|
||||
/*
|
||||
ScalaTest facilitates different styles of testing by providing traits you can mix
|
||||
together to get the behavior and syntax you prefer. A few examples are
|
||||
included here. For more information, visit:
|
||||
|
||||
http://www.scalatest.org/
|
||||
|
||||
One way to use ScalaTest is to help make JUnit or TestNG tests more
|
||||
clear and concise. Here's an example:
|
||||
*/
|
||||
import scala.collection._
|
||||
import org.scalatest.Assertions
|
||||
import org.junit.Test
|
||||
|
||||
class StackSuite extends Assertions {
|
||||
|
||||
@Test def stackShouldPopValuesIinLastInFirstOutOrder() {
|
||||
val stack = new mutable.ArrayStack[Int]
|
||||
stack.push(1)
|
||||
stack.push(2)
|
||||
assert(stack.pop() === 2)
|
||||
assert(stack.pop() === 1)
|
||||
}
|
||||
|
||||
@Test def stackShouldThrowRuntimeExceptionIfAnEmptyArrayStackIsPopped() {
|
||||
val emptyStack = new mutable.ArrayStack[String]
|
||||
intercept[RuntimeException] {
|
||||
emptyStack.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Here's an example of a FunSuite with Matchers mixed in:
|
||||
*/
|
||||
import org.scalatest.FunSuite
|
||||
import org.scalatest.Matchers
|
||||
|
||||
import org.junit.runner.RunWith
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class ListSuite extends FunSuite with Matchers {
|
||||
|
||||
test("An empty list should be empty") {
|
||||
List() should be ('empty)
|
||||
Nil should be ('empty)
|
||||
}
|
||||
|
||||
test("A non-empty list should not be empty") {
|
||||
List(1, 2, 3) should not be ('empty)
|
||||
List("fee", "fie", "foe", "fum") should not be ('empty)
|
||||
}
|
||||
|
||||
test("A list's length should equal the number of elements it contains") {
|
||||
List() should have length (0)
|
||||
List(1, 2) should have length (2)
|
||||
List("fee", "fie", "foe", "fum") should have length (4)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
ScalaTest also supports the behavior-driven development style, in which you
|
||||
combine tests with text that specifies the behavior being tested. Here's
|
||||
an example whose text output when run looks like:
|
||||
|
||||
A Map
|
||||
- should only contain keys and values that were added to it
|
||||
- should report its size as the number of key/value pairs it contains
|
||||
*/
|
||||
import org.scalatest.FunSpec
|
||||
|
||||
class ExampleSpec extends FunSpec {
|
||||
|
||||
describe("An ArrayStack") {
|
||||
|
||||
it("should pop values in last-in-first-out order") {
|
||||
val stack = new mutable.ArrayStack[Int]
|
||||
stack.push(1)
|
||||
stack.push(2)
|
||||
assert(stack.pop() === 2)
|
||||
assert(stack.pop() === 1)
|
||||
}
|
||||
|
||||
it("should throw RuntimeException if an empty array stack is popped") {
|
||||
val emptyStack = new mutable.ArrayStack[Int]
|
||||
intercept[RuntimeException] {
|
||||
emptyStack.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
core-scala/src/test/scala/samples/specs.scala
Normal file
31
core-scala/src/test/scala/samples/specs.scala
Normal file
@@ -0,0 +1,31 @@
|
||||
package samples
|
||||
|
||||
import org.junit.runner.RunWith
|
||||
import org.specs2.mutable._
|
||||
import org.specs2.runner._
|
||||
|
||||
|
||||
/**
|
||||
* Sample specification.
|
||||
*
|
||||
* This specification can be executed with: scala -cp <your classpath=""> ${package}.SpecsTest
|
||||
* Or using maven: mvn test
|
||||
*
|
||||
* For more information on how to write or run specifications, please visit:
|
||||
* http://etorreborre.github.com/specs2/guide/org.specs2.guide.Runners.html
|
||||
*
|
||||
*/
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class MySpecTest extends Specification {
|
||||
"The 'Hello world' string" should {
|
||||
"contain 11 characters" in {
|
||||
"Hello world" must have size(11)
|
||||
}
|
||||
"start with 'Hello'" in {
|
||||
"Hello world" must startWith("Hello")
|
||||
}
|
||||
"end with 'world'" in {
|
||||
"Hello world" must endWith("world")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user