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

Integration Tests for ASP.NET Core #39

Closed
14 tasks done
JeremyCaney opened this issue Mar 7, 2021 · 1 comment
Closed
14 tasks done

Integration Tests for ASP.NET Core #39

JeremyCaney opened this issue Mar 7, 2021 · 1 comment
Assignees
Labels
Area: Web Relates to the `AspNetCore` or other web-related functionality. Priority: 2 Severity 0: Nice to have Status 5: Complete Task is considered complete, and ready for deployment. Type: Improvement Improves the functionality or interface of an existing feature.
Milestone

Comments

@JeremyCaney
Copy link
Member

JeremyCaney commented Mar 7, 2021

ASP.NET Core relies on a number of framework conventions that make it cumbersome to unit test—and which, in some cases, might even limit the benefits of unit testing. This makes them well-suited for integration tests.

Scope

In particular, the following are areas that are difficult to meaningfully unit test but trivial to setup integration tests for:

  • Routing and associated extension methods
  • Dynamic selection of views based on contextual data
  • Searching for views on the file system

Performance

The most expensive part of this process is loading a comprehensive database. Given that, the optimal solution will be to establish a stub ITopicRepository with hard-coded data which can be loaded into memory.

Host

Integration testing works hand in-hand with a host project. We already have a host project. But it typically operates off of a live SqlTopicRepository in order to evaluate against real-world conditions. Can this be modified to conditionally use a stub repository, possibly by selecting an alternateStartup? Or should it be a separate, lighter weight project intended exclusively as a test harness? Likely the latter.

Tests

  • Define view by:
    • Query String
    • Header
    • Topic
  • Find views in:
    • /Views/ContentTypes/{ContentType}[.{View}].cshtml
    • /Views/{ContentType}/{ContentType|View}.cshtml
    • /Views/{Controller}/{Action}.cshtml
    • /Views/Shared/{View}.cshtml
  • Route by:
    • /{rootTopic}/{path}
    • /{area}/{path}
    • /{area?}/{controller}/{action?}/{id?}
    • /{area}/{action?}/{id?}

Git Repository

If we combine the core library, the hosts, the unit tests, and the integration tests, we’re looking at 3-5 projects which are closely related, but only loosely dependent on the other core projects. Does it make sense to move these to a new git repository? That makes good organizational sense, but makes it harder to coordinate versioning, metapackage inclusion, deeply integrated features, and testing. The latter might be solvable with conditional local project dependencies, possibly via a separate reference host repository.

@JeremyCaney JeremyCaney added Area: Web Relates to the `AspNetCore` or other web-related functionality. Type: Improvement Improves the functionality or interface of an existing feature. Status 0: Discussion Needs further evaluation of requirements and prioritization. labels Mar 7, 2021
@JeremyCaney JeremyCaney added Priority: 2 Severity 0: Nice to have Status 2: Scheduled Planned for an upcoming release. and removed Status 0: Discussion Needs further evaluation of requirements and prioritization. labels Mar 12, 2021
@JeremyCaney JeremyCaney self-assigned this Mar 12, 2021
@JeremyCaney JeremyCaney added this to the OnTopic 5.1.0 milestone Mar 12, 2021
@JeremyCaney JeremyCaney added Status 3: In Progress Currently being worked on. and removed Status 2: Scheduled Planned for an upcoming release. labels Mar 16, 2021
@JeremyCaney
Copy link
Member Author

Established a special host and StubTopicRepository exclusively for the integration tests so that they can operate against light-weight, in-memory data instead of a SQL database, thus allowing them to run in the Azure DevOps CI/CD pipeline. The integration tests themselves covers the ServiceCollectionExtensions, TopicViewLocationExpander, and TopicViewResultExecutor. Other elements of the ASP.NET Core adapter, such as the controllers and view components, may be indirectly covered by these tests, but are also covered by the existing unit tests, and thus weren't a coverage priority; the integration tests, instead, focus on the components that are difficult or impractical to unit test (e315506).

@JeremyCaney JeremyCaney added Status 5: Complete Task is considered complete, and ready for deployment. and removed Status 3: In Progress Currently being worked on. labels Mar 20, 2021
JeremyCaney added a commit that referenced this issue Apr 12, 2021
OnTopic 5.1.0 is a minor release which introduces support for mapping constructor parameters (#35) and defining what model to use when mapping associations via the `[MapAs()]` attribute (#41). Primarily, however, it is focused on bug fixes, and resolves a number of priority issues, such as an exception which occurs when deleting topics with associations (#47), topics with deleted references being treated as _unresolved_ (#46), and the inability to move a first child to another parent (#76). Finally, it also includes a number of improvements, such as checking type compatibility before mapping an association (#83), migrating the unit tests to xUnit.net (#66), and establishing integration tests for ASP.NET Core (#39).

For a full rollup of new features, improvements, and bug fixes, see Pull Request #85.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Web Relates to the `AspNetCore` or other web-related functionality. Priority: 2 Severity 0: Nice to have Status 5: Complete Task is considered complete, and ready for deployment. Type: Improvement Improves the functionality or interface of an existing feature.
Projects
None yet
Development

No branches or pull requests

1 participant