Skip to content

Instantly share code, notes, and snippets.

@geidsvig
Created July 6, 2020 18:01
Show Gist options
  • Save geidsvig/7bc7530bb4f9fb5a492b75b5bd16dc9e to your computer and use it in GitHub Desktop.
Save geidsvig/7bc7530bb4f9fb5a492b75b5bd16dc9e to your computer and use it in GitHub Desktop.
Example unit test using scala-test FlatSpecLike and other generally useful traits.
//package `your package`
import org.scalatest.{FlatSpecLike, GivenWhenThen, Matchers}
class ExampleUnitTest extends FlatSpecLike with GivenWhenThen with Matchers {
"A service/class that you want to test" should "provide some result/expectation" in {
Given("Some service/class")
def service(i: Int) = i * 2
When("some data/scenario occurs")
val result = service(2)
Then("we check the result")
val expected = 4
result shouldEqual expected
And("maybe check some more results")
assert(result != 0, "if this were to fail, this message would be printed")
}
it should "also provide some other result/expectation" in {
//nothing example using standard assert
assert(true)
}
it should "fail if hits fail() function" ignore {
fail("if not ignored this test will run and fail")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment