Packages

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
Examples:
  1. 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")
  2. ,
  3. 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

sbt-example on Github

autoImport for available sbt settings.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Example
  2. AutoPlugin
  3. PluginsFunctions
  4. Basic
  5. Plugins
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def &&(o: Basic): Plugins
    Definition Classes
    Basic → Plugins
  4. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  5. def allRequirements: PluginTrigger
    Definition Classes
    PluginsFunctions
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def buildSettings: Seq[sbt.Def.Setting[_]]
    Definition Classes
    AutoPlugin
  8. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native() @HotSpotIntrinsicCandidate()
  9. def derivedProjects(proj: ProjectDefinition[_]): Seq[Project]
    Definition Classes
    AutoPlugin
  10. def empty: Plugins
    Definition Classes
    PluginsFunctions
  11. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  12. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  13. def extraProjects: Seq[Project]
    Definition Classes
    AutoPlugin
  14. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  15. def globalSettings: Seq[sbt.Def.Setting[_]]
    Definition Classes
    Example → AutoPlugin
  16. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  17. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  18. val label: String
    Definition Classes
    AutoPlugin
  19. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  20. def noTrigger: PluginTrigger
    Definition Classes
    PluginsFunctions
  21. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  22. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  23. def projectConfigurations: Seq[Configuration]
    Definition Classes
    AutoPlugin
  24. def projectSettings: Seq[sbt.Def.Setting[_]]
    Definition Classes
    Example → AutoPlugin
  25. def requires: Plugins
    Definition Classes
    AutoPlugin
  26. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  27. def toString(): String
    Definition Classes
    AutoPlugin → AnyRef → Any
  28. def trigger: PluginTrigger
    Definition Classes
    AutoPlugin
  29. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  31. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. 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._

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] ) @Deprecated
    Deprecated

Inherited from AutoPlugin

Inherited from PluginsFunctions

Inherited from Basic

Inherited from Plugins

Inherited from AnyRef

Inherited from Any

Ungrouped