You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
- Do you have control over the API code? Is there a "test" version of the API?Ryan Wilson– Ryan Wilson2025-06-09 12:27:20 +00:00Commented Jun 9 at 12:27
- If you are using Entity framework core you might consider the in-memory database providerJonasH– JonasH2025-06-09 12:51:01 +00:00Commented Jun 9 at 12:51
- You probably want to use a separate test version of a database, otherwise this is just doomed to fail rather badly. Do you have such a version? And can you easily control if transactions are test or not?siggemannen– siggemannen2025-06-09 12:51:03 +00:00Commented Jun 9 at 12:51
- "most of my tests interact with the application via its API endpoints" this is where your problem is. Most of your tests should be unit tests. You are describing integration tests and they should be very much the minority. You say that you can run direct sql from your tests, so for the very small number of integration tests that cause data changes, your test code can insert test data and clean up afterwards.iakobski– iakobski2025-06-09 13:27:23 +00:00Commented Jun 9 at 13:27
- To expand on that. You have an API endpoint A. A does nothing apart from pass the parameters directly to class B. B converts your parameters into the internal data model and calls C. C contains the business logic and needs to save or retrieve data. It calls class D which contains only the database CRUD (or equivalent). You test D by writing tests that instantiate D and interact with the dev database, in a transaction. This proves D works. You test C by injecting a mock or stub D which returns test data. You know your mock D behaves the same as real D because you have tests of D by itself...iakobski– iakobski2025-06-09 13:39:15 +00:00Commented Jun 9 at 13:39
| Show 2 more comments
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
- create code fences with backticks ` or tildes ~ ```
like so
``` - add language identifier to highlight code ```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible) <https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. python-3.x), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you
default