-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add Akka.Hosting.TestKit module #102
Add Akka.Hosting.TestKit module #102
Conversation
…Hosting into Add_Akka.Hosting.TestKit
|
Tests are passing |
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.
By way of example, let's refactor at least 1 of the existing test suites in Akka.Hosting to use the TestKit
. If there are issues with friction / the ease of use of the API that would be a valuable way to discover it before we push this out to end users.
I think https://github.com/akkadotnet/Akka.Hosting/tree/dev/src/Akka.Persistence.Hosting.Tests is a good candidate for testing out the new Akka.Hosting TestKit - not too big, reasonably complex use cases. |
One snag that I've seen so far: This TestKit can only be used if a spec uses the same hosting configuration for all its unit test. If the unit tests were testing different hosting configurations, then the only way to use the test kit is to split each unit tests into classes. |
A proof of concept implementation of Akka.Hosting test kit.
Comments and reviews are welcome.
Configuring the spec
The biggest difference is that, since the test is started asynchronously, the TestKit properties and methods would not be available in the unit test class constructor anymore. Since the spec depends on Microsoft HostBuilder, configuration has to be broken down into steps. There are overridable methods that user can use to override virtually all of the setup process.
The steps of what overridable methods gets called is:
ConfigureLogging(ILoggingBuilder)
-- Add custom logger and filtering rules here.ConfigureHostConfiguration(IConfigurationBuilder)
-- Inject any additional hosting environment configuration here, such as faking environment variables.ConfigureAppConfiguration(HostBuilderContext, IConfigurationBuilder)
-- Inject the application configuration here.ConfigureServices(HostBuilderContext, IServiceCollection)
-- Add additional services needed by the test here, such as mocked up services used inside the dependency injection.Config
property, it is not passed as part of the constructor anymore.ConfigureAkka(AkkaConfigurationBuilder, IServiceProvider)
-- This is called insideAddAkka
, use this to configure theActorSystem
BeforeTestStart()
method. This method is called after the TestKit is initialized. Move all of the codes that used to belong in the constructor here.Akka.Hosting.TestKit
extendsAkka.TestKit.Xunit2
directly, all testing methods are available out of the box.All of the properties, such as
Sys
andTestActor
will be available once the unit test class is invoked.NOTES
Would not compile until akkadotnet/akka.net#6093 is merged and released