Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andimiller/munit-cats-effect-styles
Some Suites for munit-cats-effect
https://github.com/andimiller/munit-cats-effect-styles
cats functional-programming munit scala testing
Last synced: about 3 hours ago
JSON representation
Some Suites for munit-cats-effect
- Host: GitHub
- URL: https://github.com/andimiller/munit-cats-effect-styles
- Owner: andimiller
- License: mit
- Created: 2021-09-21T21:45:06.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-05-20T22:59:03.000Z (over 1 year ago)
- Last Synced: 2024-01-29T22:45:07.314Z (10 months ago)
- Topics: cats, functional-programming, munit, scala, testing
- Language: Scala
- Homepage:
- Size: 18.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# munit-cats-effect-styles
This is a library for adding ScalaTest style testing layouts for munit with cats-effect.
This may seem quite opinionated, and it is, this is just the way I like to test things, although I am open to expanding it.
It's cross published for Scala 2.12, 2.13 and 3, scala JVM and scala JS, and cats-effect 2 and 3.
## Dependencies
It's published to maven central and only depends on `munit-cats-effect`.
```scala
// for cats-effect-2
libraryDependencies += "net.andimiller" %%% "munit-cats-effect-2-styles" % "1.0.0" % Test
testFrameworks += new TestFramework("munit.Framework")
// for cats-effect-3
libraryDependencies += "net.andimiller" %%% "munit-cats-effect-3-styles" % "1.0.0" % Test
testFrameworks += new TestFramework("munit.Framework")
```For `scala-native` support, or the latest munit milestones, please use the non-versioned dependency, which is cats-effect-3 only:
```scala
libraryDependencies += "net.andimiller" %%% "munit-cats-effect-styles" % "2.0.0-M1" % Test
testFrameworks += new TestFramework("munit.Framework")
```## Styles
### FlatSpecSame as the ScalaTest style, this lets you write tests with the word `should` in the middle.
Since we're assuming cats-effect, the body for your `in` should be either an `IO[Any]` or a scalacheck `Prop`.
```scala
import cats.effect.IO
import org.scalacheck.Prop.forAll
import net.andimiller.munit.cats.effect.styles.FlatIOSpecclass FlatIOSpecSpec extends FlatIOSpec {
"a subject" should "do stuff" in {
IO { 1234 }.assertEquals(1234)
}"another subject" should "meet a property" in {
forAll { (s: String) => s.reverse.reverse == s }
}}
```### WordSpec
Same as the ScalaTest style, this lets you write nested tests using `should` and then `in`.
Since we're assuming cats-effect, the body for your `in` should be either an `IO[Any]` or a scalacheck `Prop`.
```scala
import cats.effect.IO
import net.andimiller.munit.cats.effect.styles.WordIOSpec
import org.scalacheck.Prop.forAllclass WordIOSpecSpec extends WordIOSpec {
"subject" should {
"test one" in {
IO {
1234
}.assertEquals(1234)
}
"test two" in {
interceptIO[Throwable](
IO {
throw new Exception
}
)
}
"some property" in {
forAll { (s: String) =>
s.reverse.reverse == s
}
}
}}
```