-
Notifications
You must be signed in to change notification settings - Fork 560
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
Issue 338 - Unit Tests Run Slow #340
base: master
Are you sure you want to change the base?
Conversation
@@ -250,3 +250,9 @@ paket-files/ | |||
# JetBrains Rider | |||
.idea/ | |||
*.sln.iml | |||
|
|||
# NCrunch |
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.
Oh, and I added NCrunch to the .gitignore. It's not technically related to the PR, and I'm happy to separate it out if you like.
|
||
namespace AbpCompanyName.AbpProjectName.Tests.UnitTests.FakeServices | ||
{ | ||
public class FakeLogger : NullLogger, ILogger |
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.
Technically I guess the FakeLogger isn't really required for this PR, but I used it a lot for verifying logging in my unit tests. I'm happy to remove it if you like.
|
||
private UserAppService GetUserAppService(IRepository<Role> roleRepository, IRepository<User, long> userRepository) | ||
{ | ||
// todo: extract an interface for UserManager and use it in UserAppService to simplify mocking and remove all the null args |
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.
I don't know if adding an interface for UserManager and RoleManager etc is on the roadmap, but using their concrete classes in the constructor injection makes pure unit testing much harder and more brittle.
Thanks a lot @lprichar 👍 Fixes #338 |
@lprichar we have reviewed your PR and it is very good I think but we thought that this will be a bit complex for a startup template. We will keep this PR open and use it as an example for the ones who face the same performance problem on their proejcts. Thanks again for your great contribution 😄 . |
…ferentiate them from parallel ones in the Unit test folder
Summary
Introduces the option of writing light-weight, fast-running unit tests in addition to the current in-memory database style integration tests. The key to this functionality is the new
.AsRepository()
extension method (see below).Details
IntegrationTests\
folder and adjusts namespaces\UnitTests
folder for placing fast tests intoAbpProjectNameUnitTestBase
andAbpProjectNameUnitTestModule
into\UnitTests
that unit tests will inherit from and useAbpProjectNameTestBase
toAbpProjectNameIntegrationTestBase
to keep the base classes clearly differentiatedAsRepository()
extension method that creates working IRepository mocks given lists of objects (or single objects)UnitTests\Users\UserAppService_Tests.cs
primarily for documentation purposesTo Test
UnitTests\Users\UserAppService_Tests.cs
Expected: They should all pass