|
QuickStart
Your first specification starts here!
Featured (for more information, take a look at the User Guide)
import org.specs._ class helloWorld extends Specification import org.specs._
class helloWorld extends Specification {
"'hello world' has 11 characters" in {}
"'hello world' matches 'h.* w.*'" in {}
}import org.specs._
class helloWorld extends Specification {
"'hello world' has 11 characters" in {
"hello world".size must_== 11
}
"'hello world' matches 'h.* w.*'" in {
"hello world" must be matching("h.* w.*")
}
}Specification "helloWorld" specifies + 'hello world' has 11 characters + 'hello world' matches 'h.* w.*' Total for specification "helloWorld": Finished in 0 second, 63 ms 2 examples, 2 assertions, 0 failure, 0 error import org.specs._
class helloWorld extends Specification {
"hello world" should {
"have 11 characters" in {
"hello world".size must_== 11
}
"match 'h.* w.*'" in {
"hello world" must be matching("h.* w.*")
}
}
"Good bye cruel world" should {...}
}class helloWorldTest extends SpecificationWithJUnit { ... }Note: helloWorldTest is declared as a class and not an object to be instantiated properly by JUnit runners.
| |
► Sign in to add a comment
5. now, you can add more structure to your specification
No joy getting helloWorld Specification to run: specs1.6.1, scala 2.7.7.final, java1.6.0_15 on OS X
scalac -cp ~/work/specs1.6.1/specs-1.6.1.jar helloWorld.scala scala -cp .:~/work/specs1.6.1/specs-1.6.1.jar helloWorld Exception in thread "main" java.lang.NoClassDefFoundError??: org/specs/matcher/Matcher
Caused by: java.lang.ClassNotFoundException??: org.specs.matcher.MatcherRobert: this tripped me up too a while back. I'm not sure which shell derivative OS X uses, but in bash, the "~" character does not expand to your home directory when embedded, eg:
$ echo ~ /home/YourUserName? $ echo .:~ .:~
Spell out the full path and it should work, eg "scala -cp .:/home/YourUserName?/work/..."
Let's try again, now with wiki-fu at the ready:
I created a Scala class which extends SpecificationWithJUnit. When I try to run it with Eclipse's JUnit runner (Run As > JUnit Test), no tests are found and a message is shown: No tests found with test runner 'JUnit 4'.
The project references junit-4.7.jar. Do I have to add a JUnit test suite (by means of Java code) in order to make JUnit aware of the Scala test classes?
grimmfrank : check this http://www.scala-lang.org/node/363
> compile and run the class named helloWorld: scala -cp specs-<version>.jar run helloWorld:
Add ".:" to the classpath there to avoid tearing your hair out.
No luck with scala 2.8.1.final, java 1.6.0_20 and specs_2.8.1-1.6.6
scala -cp specs_2.8.1-1.6.6.jar:. run helloWorld.scala
Gives no output whatsoever. No errors, just nothing.
Solution: scalac -cp specs_2.8.1-1.6.6.jar helloWorld.scala scala -cp specs_2.8.1-1.6.6.jar:. run helloWorld
Does work of course, the instructions seemed to imply it would run as a script.
Here's a quick bash script I've hacked together. Just update the SPECSJAR var to your path and version
SPECSJAR=/my/path/to/specs/specs_2.8.1-1.6.6.jar