Skip to content
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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

lprichar
Copy link
Contributor

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

  • Moves all existing test infrastructure into an IntegrationTests\ folder and adjusts namespaces
  • Adds a \UnitTests folder for placing fast tests into
  • Adds a AbpProjectNameUnitTestBase and AbpProjectNameUnitTestModule into \UnitTests that unit tests will inherit from and use
  • Renames AbpProjectNameTestBase to AbpProjectNameIntegrationTestBase to keep the base classes clearly differentiated
  • Adds classes: TestQueryable, TestAsyncQueryProvider, TestAsyncEnumerable, and TestAsyncEnumerator, all of which provide the infrastructure for LINQ queries against in-memory lists of data
  • Adds an AsRepository() extension method that creates working IRepository mocks given lists of objects (or single objects)
  • Adds several unit tests for UserAppService into UnitTests\Users\UserAppService_Tests.cs primarily for documentation purposes

To Test

  1. Run the tests in UnitTests\Users\UserAppService_Tests.cs

Expected: They should all pass

@@ -250,3 +250,9 @@ paket-files/
# JetBrains Rider
.idea/
*.sln.iml

# NCrunch
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

@ismcagdas ismcagdas added this to the v4.2 milestone Oct 15, 2018
@ismcagdas
Copy link
Member

ismcagdas commented Oct 15, 2018

Thanks a lot @lprichar 👍
We will check it for v4.2 milestone.

Fixes #338

@ismcagdas ismcagdas modified the milestones: v4.2, v4.3 Oct 15, 2018
@alirizaadiyahsi alirizaadiyahsi modified the milestones: v4.2.1, v4.3 Nov 13, 2018
@ismcagdas
Copy link
Member

@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 😄 .

@ismcagdas ismcagdas removed this from the v4.3 milestone Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants