Instance Constructors
-
new
example(files: String*)
Value Members
-
final
def
!=(arg0: Any): Boolean
-
final
def
##(): Int
-
def
+(other: String): String
-
def
->[B](y: B): (example, B)
-
final
def
==(arg0: Any): Boolean
-
def
apply(defn: Any): Any
-
final
def
asInstanceOf[T0]: T0
-
def
clone(): AnyRef
-
-
-
-
-
-
-
def
finalize(): Unit
-
def
formatted(fmtstr: String): String
-
final
def
getClass(): Class[_]
-
def
hashCode(): Int
-
final
def
isInstanceOf[T0]: Boolean
-
-
final
def
notify(): Unit
-
final
def
notifyAll(): Unit
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
-
def
toString(): String
-
final
def
wait(): Unit
-
final
def
wait(arg0: Long, arg1: Int): Unit
-
final
def
wait(arg0: Long): Unit
-
def
→[B](y: B): (example, B)
Inherited by implicit conversion any2stringadd from
example to any2stringadd[example]
Inherited by implicit conversion StringFormat from
example to StringFormat[example]
Inherited by implicit conversion Ensuring from
example to Ensuring[example]
Inherited by implicit conversion ArrowAssoc from
example to ArrowAssoc[example]
Generates unit tests from examples in Scaladoc in
files
.Getting started
Suppose you have a source file
src/main/scala/yourPackage/YourClass.scala
, which contains some code examples in its Scaladoc. You can run those examples as test cases with this library.Step 1: Add this library as test dependency
Add the following code in your
build.sbt
:Step 2: Create the test suite class
Create a source file at
src/test/scala/yourPackage/YourClassSpec.scala
, with the following content:The
@example
annotation will extract code in Scaladoc insrc/main/scala/yourPackage/YourClass.scala
as a org.scalatest.FreeSpecStep 3: Run tests
You will notice that all code blocks inside
{{{ }}}
in Scaladoc comments insrc/test/scala/yourPackage/YourClass.scala
are executed.Common code
Code blocks before any Scaladoc tag are shared by all test cases. For example:
import org.scalatest._, Matchers._
Then Scalatest matchers will be available for all test cases.
Author:
杨博 (Yang Bo) <[email protected]>
A code block under a Scaladoc tag is a test case. The test case is inside a org.scalatest.FreeSpec
this should be(a[FreeSpec])
A code block may define variables.
Those variables are accessible from other code blocks under the same Scaladoc tag.
i should be(1)
s should be("text")
A variable defined under a Scaladoc tag is not accessible from code blocks under another tags.
"i" shouldNot compile
example.scala on Github