Monadic Fixtures

30 views
Skip to first unread message

Topher

unread,
Apr 13, 2012, 1:18:03 PM4/13/12
to scalate...@googlegroups.com
I'm writing integration tests which require mixing several fixtures, often in different ways for each test.  I had cast about for solutions, but I didn't feel quite satisfied with the options noted in the Scalatest documentation, nor with the managed fixtures posted back in February. I realized that Scala's for statements were meant to clean-up the patterns I was using, so I wrote these:  https://gist.github.com/2378392.  I'm sharing them here because you might find them useful or have some keen insights.  I have already had one: now that I've written these, they feel like Scala ARM.  Perhaps that's a good solution for creating and combining test fixtures.

Bill Venners

unread,
Apr 13, 2012, 6:54:14 PM4/13/12
to scalate...@googlegroups.com
Hi Topher,

Interesting. Thanks for posting this. The way I would have probably
tried to do this is with is the loan pattern. I.e., instead of:

for {
(httpPort, httpsPort) <- withServer()
driver <- withChromeDriver()
(empId, depId) <- loadDbWithEmpAndDep()
} {
...do the test...
}

I'd probably try something like:

withServer { (httpPort, httpsPort) =>
withChromeDriver { driver =>
withDBLoadedWithEmpAndDep { (empId, depId) =>
...do the test...
}
}
}

Is there something you need that you can't get from the loan pattern
that you can get with the for comprehensions?

Thanks.

Bill

> --
> You received this message because you are subscribed to the Google
> Groups "scalatest-users" group.
> To post to this group, send email to scalate...@googlegroups.com
> To unsubscribe from this group, send email to
> scalatest-use...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/scalatest-users?hl=en
> ScalaTest itself, and documentation, is available here:
> http://www.artima.com/scalatest

--
Bill Venners
Artima, Inc.
http://www.artima.com

Vlad Patryshev

unread,
Apr 13, 2012, 7:25:49 PM4/13/12
to scalate...@googlegroups.com
I concur. Here's one of my typical pieces of code.

    "add a sharepoint repo, list it, then delete" in {
      testsEnabledREPOPC must beTrue.orSkip

      val repoName = Utility.nonce(4)
      val testRepo = sharepointRepo(repoName)

      commit("Adding a sharepoint repo") { ops => ops.setPCFields(components(REPOPC), testRepo, "update", "0") }

      withRepoContent(REPOPC) { repo =>
        !repo.isEmpty aka "Some repos expected in repo with new entry" mustBe true
... etc
]
Thanks,
-Vlad

Topher

unread,
Apr 14, 2012, 9:43:42 AM4/14/12
to scalate...@googlegroups.com
Hi Bill,

Thanks for having a look at it.  You ask a very good question, and after thinking about it, I like this style over the applicative style for only one reason: its aesthetic.  First, the newly bound symbols are on the left, like assignment operators and variable declarations in so many programming languages.  And second, the indentation remains constant regardless of how many fixtures a test requires.

Cheers,
Topher.
Reply all
Reply to author
Forward
0 new messages