-
Couldn't load subscription status.
- Fork 1.4k
WIP: Create TestEnvironment #1255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| } | ||
|
|
||
| object testConsole { | ||
| def feedLines(lines: String*): ZIO[TestEnvironment, Nothing, Unit] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine for this pull request, but in general, I think I'd put these helpers inside the companion objects of the Test* classes.
e.g.:
TestConsole.feedLines(...)Then there's a logical place for users to look for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think this makes sense. One thing I am thinking about is whether it makes sense to have something like:
trait TestConsole extends Console {
val console: TestConsoleImplementation
}
case class TestConsoleImplementation extends Console.Service[Any]
That way when we define these helper methods we can only depend on the specific environment type that these methods require and users could get the benefit of the method if they only depend on certain mock objects instead of the mock environment. Not sure about naming. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right. Let's follow the ZIO conventions though:
trait MockConsole extends Console {
val console: MockConsole.Service[Any]
}
object MockConsole {
trait Service[R] extends Console.Service[R] { def feedLines(...) }
def feedLines(lines: String*): ZIO[MockConsole, Nothing, Unit] = ...
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. I'm on it!
|
|
||
| object TestEnvironment { | ||
|
|
||
| val Value: Managed[Nothing, TestEnvironment] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more organizational tip:
Let's rename TestEnvironment => TestEnvironmentInternals, and make it package private (private[test]).
Then inside zio.test.mock package object, we can do:
package object mock {
val TestEnvironment: TestEnvironment = TestEnvironmentInternals.Value
}Then a user has type TestEnvironment and can use value TestEnvironment, which is more Scala-idiomatic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, actually, I'm not so sure about this, because TestEnvironment.Value has type Managed[...]. So let's leave this the way it is.
We can add this value in package object mock:
val TestEnvironmentManaged: Managed[TestEnvironment] = TestEnvironment.ValueIn fact, it probably makes sense to rename TestEnvironment.Value to TestEnvironment.ManagedDefault (a managed, default test environment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on this pull request! It's all coming together nicely.
Just one small change and we can ship it.
|
@adamgfraser Can you do the |
|
@jdegoes Yes. |
|
Er, mock rename for |
|
@jdegoes This is ready for another review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superb work! These changes add tremendous value to the testkit.
|
@jdegoes Thanks! Means a lot coming from you. |
* create TestEnvironment * address review comments * add additional convenience methods * rename TestEnvironment to MockEnvironment * refactor to create mock interfaces and services * add some tests
Creates a
TestEnvironmentas proposed in #1129. Will add more convenience functions and tests once #1252 is merged but wanted to get this out there.