seratch / testgenerator   1.1.1

GitHub

Scala test generator sbt plugin

Scala versions: 2.10
sbt plugins: 0.13

Scala test generator sbt plugin

How to setup

Add this plugin to project/plugins.sbt

Delete project/plugins directory if it exists and edit project/plugins.sbt as follows:

addSbtPlugin("com.github.seratch" %% "testgenerator" % "1.1.1")

Add the settings to built.sbt

testgeneratorSettings

Run sbt

See also: https://github.com/harrah/xsbt/wiki/Setup

Specify a filename

src/main/scala/com/example/models.scala:

package com.example
case class Staff(id: Long, name: String, ...)
case class Company(id: Long, name: String, ...)
case class Stock(id: Long, itemId: Long, ...)

And specify the above file:

$ sbt
> test-gen com/example/models.scala
"com.example.StaffSpec" already exists.
"com.example.CompanySpec" already exists.
"com.example.StockSpec" created.

Specify a class name

If you specify a class name, it must be the name of the source file.

"com.example.MyApp" will be translated as "src/main/scala/com/example/MyApp.scala".

$ sbt
> test-gen com.example.MyApp
"com.example.MyAppSpec" created.

Specify a directory

"test-gen" will search targets recursively under the directory.

$ sbt
> test-gen com/example

Specify a package name

The same as specifying a directory.

$ sbt
> test-gen com.example
"com.example.MyAppSpec" created.
"com.example.util.MyUtilSpec" created.

Configuration

Please add the following line at the top of your buid.sbt:

import testgenerator.SbtKeys._

and then,

testgeneratorSettings

testgeneratorEncoding in Compile := "UTF-8"

testgeneratorTestTemplate in Compile := "scalatest.FlatSpec"

testgeneratorScalaTestMatchers in Compile := "ShouldMatchers"

testgeneratorWithJUnitRunner in Compile := false 

testgeneratorLineBreak in Compile := "LF"

testgeneratorTestTemplate

testgenScalaTestMatchers

Happy Testing! :)