You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: TestArena/Blog/IntegrationTesting/Intro/Index.razor
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -206,6 +206,6 @@ public async Task Get_ById_SuperHero_Returns_SuperHero()
206
206
<p>Such scenarios highlight the importance of integration tests in catching unintended changes or bugs in the application behavior.</p>
207
207
</Section>
208
208
<p>This is it for the basic setup demo. I will be covering more in the future articles like, how to work with database, authentication, events etc.</p>
<p>Welcome to the 2nd post in our Integration testing series. You may check out the previous post that introduces the concept of writing integration tests using <b>WebApplicationFactory</b> in dotnet below:</p>
59
+
<BlogReferenceCard
60
+
Title="Integration testing for dotnet core APIs: Introduction"
61
+
Description="Integration testing for dotnet core APIs: Introduction"
<p>Almost every application relies on persistent storage, typically through a database. Integration testing with a real database can be challenging, especially when trying to maintain isolation and consistency across tests. In this post, we will explore how to effectively manage database dependencies in integration tests using <b>WebApplicationFactory</b> and containerized databases.</p>
67
+
<p><b>Pre-requisites</b>, in case you want to follow the same setup on your system:</p>
68
+
<ul>
69
+
<li><b>Postgres DB Server:</b> This is needed in case you want to test out the main application.</li>
70
+
<li><b>Docker:</b> This is needed to run test containers.</li>
71
+
</ul>
72
+
</Section>
73
+
74
+
<SectionHeading="Setting Up the Database"Level="4">
75
+
<p>To do this we need to first introduce a database in our sample superhero API. For this demo purpose, we have used a Postgres database.</p>
76
+
<p>For this, we made the below changes in our superhero API:</p>
77
+
<CodeSnippetDescription="Connection String in appsettings.json"Number="2">
<p>Install the package <b>Npgsql.EntityFrameworkCore.PostgreSQL</b> in the main API project. After that, we need to provide options in the program file to guide the application to use the Postgres database:</p>
85
+
<CodeSnippetDescription="Configuring DbContext in Program.cs"Number="3">
<li>Now before any of the tests will start executing, our <b>SharedFixture</b> code will run and it will fire up the test container as you can see in the below image:</li>
121
+
</ul>
122
+
<BlogImageImagePath="/images/blog/integration-testing/handling-database/Test containers in action.webp"
123
+
Description="Test containers in action"Number="2" />
124
+
<ul>
125
+
<li>In the <b>Arrange</b> step, I added a few records directly to the database using the <b>SharedFixture</b>.</li>
126
+
<li>After the above step, there are some records in the system and in the <b>Act</b> step, we will be trying to call the GET superheroes API.</li>
127
+
<li>If everything is correct, we should be able to see our tests being passed like below:</li>
Copy file name to clipboardExpand all lines: TestArena/Blog/PactNet/handling-events/Index.razor
+6-1Lines changed: 6 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,12 @@
10
10
<p>This is a continuation of the PACT for .NET series where I am going to cover the usage of PACT in event-based systems.</p>
11
11
<p>This article assumes the readers will have a basic understanding of event-based systems and frameworks. In case not, a good place to start can be <ahref="https://www.rabbitmq.com/tutorials">RabbitMQ Tutorials</a>.</p>
12
12
<p>I will be using the same repo setup that I have used to demonstrate usage in API-based systems. I have covered the setup in detail in a previous blog in this series:</p>
13
-
<p><ahref="/blog/contract-testing-pact-net-intro">Contract testing for APIs: Intro to PACT for .NET Core</a></p>
13
+
<BlogReferenceCard
14
+
Title="Contract testing for APIs: Intro to PACT for .NET Core"
15
+
Description="Intro to PACT for .NET Core: API contract testing"
0 commit comments