Reputation: 34423
I am converting some QUnit Javascript tests to Scala. The tests I have look like this:
class XXX extends MyTests {
test("equals", () => {
val a = new XXX(x)
val b = new XXX(y)
ok(a.x != b.x, "Passed!")
ok(a.y != b.y, "Passed!")
ok(!a.equals(b), "Passed!")
ok(!b.equals(a), "Passed!")
a.copy(b)
ok(a.x == b.x, "Passed!")
ok(a.y == b.y, "Passed!")
ok(a.equals(b), "Passed!")
ok(b.equals(a), "Passed!")
})
}
MyTests
is my trait derived from ScalaTest FunSuite
I could replace ok
with assert
in the code, or I can place following in MyTests
:
def ok(ok: Boolean, message: String) = assert(ok, message)
First solution results in better tests, as using assert
directly means ScalaTest
enhanced macro implementation of assert
is used. Second solution is much less work, as I do not have to replace ok
in the code.
Is there some way how to import assert
under a different name from FunSuite
or otherwise forward my implementation to the ScalaTest macro, so that ok
behaves exactly as assert
?
Upvotes: 1
Views: 50