object Example extends AutoPlugin
Generates unit tests from examples in Scaladoc.
Getting started
Suppose you have some source files under src/main/scala
, which contain
some code examples in their Scaladoc. You can run those examples as test
cases with this library.
Step 1: Add this plug-in in your sbt settings
// project/plugins.sbt
addSbtPlugin("com.thoughtworks.example" % "sbt-example" % "latest.release")
// build.sbt
enablePlugins(Example)
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.10" % Test
Step 2: Run tests
sbt test
You will notice that all code blocks inside
{{{
}}}
in Scaladoc
comments under src/main/scala
are executed.
Common code
Code blocks before any Scaladoc tag are shared by all test cases. For example:
import org.scalatest.freespec.AnyFreeSpec
Then the name FreeSpec
will be available for all test cases.
sbt test
You will notice that all code blocks inside
{{{
}}}
in Scaladoc
comments under src/main/scala
are executed.
Common code
Code blocks before any Scaladoc tag are shared by all test cases. For example:
import org.scalatest.freespec.AnyFreeSpec
Then the name FreeSpec
will be available for all test cases.
Author:
杨博 (Yang Bo) <[email protected]>
- Source
- Example.scala
A code block may define variables.
val i = 1 val s = "text"
Those variables are accessible from other code blocks under the same Scaladoc tag.
i should be(1)
s should be("text")
, A code block under a Scaladoc tag is a test case. The test case is inside an org.scalatest.freespec.AnyFreeSpec
this should be(an[AnyFreeSpec])
- Note
A variable defined under a Scaladoc tag is not accessible from code blocks under another tag.
"i" shouldNot compile
- See also
autoImport for available sbt settings.
- Alphabetic
- By Inheritance
- Example
- AutoPlugin
- PluginsFunctions
- Basic
- Plugins
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
&&(o: Basic): Plugins
- Definition Classes
- Basic → Plugins
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
allRequirements: PluginTrigger
- Definition Classes
- PluginsFunctions
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
buildSettings: Seq[sbt.Def.Setting[_]]
- Definition Classes
- AutoPlugin
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native() @HotSpotIntrinsicCandidate()
-
def
derivedProjects(proj: ProjectDefinition[_]): Seq[Project]
- Definition Classes
- AutoPlugin
-
def
empty: Plugins
- Definition Classes
- PluginsFunctions
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
extraProjects: Seq[Project]
- Definition Classes
- AutoPlugin
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
globalSettings: Seq[sbt.Def.Setting[_]]
- Definition Classes
- Example → AutoPlugin
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
val
label: String
- Definition Classes
- AutoPlugin
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
noTrigger: PluginTrigger
- Definition Classes
- PluginsFunctions
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
projectConfigurations: Seq[Configuration]
- Definition Classes
- AutoPlugin
-
def
projectSettings: Seq[sbt.Def.Setting[_]]
- Definition Classes
- Example → AutoPlugin
-
def
requires: Plugins
- Definition Classes
- AutoPlugin
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AutoPlugin → AnyRef → Any
-
def
trigger: PluginTrigger
- Definition Classes
- AutoPlugin
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
object
autoImport
Contains sbt setting keys, which will be automatically imported into your
build.sbt
.Contains sbt setting keys, which will be automatically imported into your
build.sbt
.You need to manually import this autoImport object in
.scala
files, e.g. an sbt plugin, or this Scaladoc.import com.thoughtworks.Example.autoImport._