Skip to content

Commit a5da3ef

Browse files
committed
✏️ Update SiteMap and add new TDD intro files
- Updated sitemap.xml for improved navigation structure. - Added new banner and thumbnail SVG files for TDD introduction. - Created Intro.razor for TDD content presentation. - Enhanced overall content clarity and organization. Generated by Copilot
1 parent 48c664d commit a5da3ef

File tree

5 files changed

+138
-0
lines changed

5 files changed

+138
-0
lines changed

TestArena/Blog/Common/NavigationUtils/SiteMap.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ public static class SiteMap
144144
new DateTime(2025, 9, 06),
145145
"images/blog/ai/open-ai-structured-output/banner.png",
146146
["AI", "OpenAI", "API", "Structured Output", ".NET", "C#"]),
147+
new("Test Driven Development: Getting started with TDD in .NET",
148+
"/blog/tdd/introduction",
149+
new DateTime(2025, 9, 20),
150+
"images/blog/tdd/intro/banner.svg",
151+
["TDD", "Test Driven Development", ".NET", "C#"]),
147152
];
148153

149154
//"/blog/ai/openai-rest-api/structured-output"

TestArena/Blog/TDD/Intro.razor

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
@page "/blog/tdd/introduction"
2+
@using TestArena.Blog.Common
3+
@using TestArena.Blog.Common.NavigationUtils
4+
5+
<style>
6+
table {
7+
border-collapse: collapse;
8+
width: 100%;
9+
margin: 20px 0;
10+
}
11+
th, td {
12+
padding: 12px;
13+
border: 1px solid #ddd;
14+
text-align: left;
15+
}
16+
th {
17+
background-color: #f0f0f0;
18+
}
19+
</style>
20+
21+
@code{
22+
PageInfo currentPage = SiteMap.Pages.FirstOrDefault(x => x.RelativePath == "/blog/tdd/introduction");
23+
}
24+
25+
<BlogContainer>
26+
27+
28+
<Header Title="Test Driven Development (TDD): A Practical Introduction"
29+
Image="@currentPage.ArticleImage" PublishedOn="@currentPage.PublishedOn" Authors="Ajay Kumar">
30+
</Header>
31+
32+
<Section>
33+
<p>Test Driven Development (TDD) is a disciplined approach to software development where you write tests <b>before</b> you write the code. Instead of coding and hoping nothing breaks, TDD gives you a safety net and a clear workflow for building robust features.</p>
34+
<p>In this post, we’ll break down the TDD cycle, address common misconceptions, and walk through a simple example in C#.</p>
35+
</Section>
36+
37+
<Section Heading="The TDD Cycle: Red, Green, Refactor">
38+
<ul>
39+
<li><b>Red:</b> Write a test for a new feature. It should fail, since the feature doesn’t exist yet.</li>
40+
<li><b>Green:</b> Write the minimum code needed to make the test pass.</li>
41+
<li><b>Refactor:</b> Clean up the code, keeping all tests green.</li>
42+
</ul>
43+
<p>This loop is repeated for every new piece of functionality. It’s simple, but it fundamentally changes how you design and maintain code.</p>
44+
</Section>
45+
46+
<Section Heading="Common Myths About TDD">
47+
<ul>
48+
<li><b>“TDD slows you down.”</b> It may feel slower at first, but it saves hours of debugging and regression fixes in the long run.</li>
49+
<li><b>“TDD is just about testing.”</b> Actually, TDD is a design technique. Tests guide your architecture and help you write modular, maintainable code.</li>
50+
<li><b>“TDD only works for simple problems.”</b> TDD is even more valuable for complex domains, where breaking problems into small, testable steps is crucial.</li>
51+
</ul>
52+
</Section>
53+
54+
<Section Heading="A Simple Example: Adding Two Numbers">
55+
<p>Let’s see TDD in action with a basic C# example. Suppose we want a method that adds two numbers.</p>
56+
<ol>
57+
<li><b>Write a failing test (Red):</b></li>
58+
</ol>
59+
<CodeSnippet Description="Failing test for Add method" Number="1">
60+
using Xunit;
61+
62+
public class CalculatorTests
63+
{
64+
[Fact]
65+
public void Add_TwoNumbers_ReturnsSum()
66+
{
67+
var calc = new Calculator();
68+
var result = calc.Add(2, 2);
69+
Assert.Equal(4, result);
70+
}
71+
}
72+
</CodeSnippet>
73+
<p>This test fails because <code>Calculator</code> doesn’t exist yet.</p>
74+
<ol start="2">
75+
<li><b>Write minimal code to pass (Green):</b></li>
76+
</ol>
77+
<CodeSnippet Description="Minimal code to pass the test" Number="2">
78+
public class Calculator
79+
{
80+
public int Add(int a, int b) => a + b;
81+
}
82+
</CodeSnippet>
83+
<p>Now the test passes. If the code is already clean, you may not need to refactor. In real projects, this is where you improve names, remove duplication, or reorganize logic—confident that your tests have your back.</p>
84+
</Section>
85+
86+
<Section Heading="Why TDD Matters">
87+
<p>TDD isn’t about writing more tests. It’s about building confidence in your codebase, enabling safe refactoring, and letting tests drive better design decisions. The process scales from trivial methods to complex systems.</p>
88+
</Section>
89+
90+
<Section>
91+
<p>In the next post, we’ll tackle a slightly more complex problem (like FizzBuzz or a String Calculator) and walk through the TDD process step by step.</p>
92+
<p>Have you tried TDD before? What worked, what didn’t? Share your experience in the comments below.</p>
93+
</Section>
94+
</BlogContainer>
Lines changed: 17 additions & 0 deletions
Loading
Lines changed: 17 additions & 0 deletions
Loading

TestArena/wwwroot/sitemap.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,9 @@
125125
<lastmod>2025-09-06</lastmod>
126126
<changefreq>monthly</changefreq>
127127
</url>
128+
<url>
129+
<loc>https://devcodex.in/blog/tdd/introduction</loc>
130+
<lastmod>2025-09-21</lastmod>
131+
<changefreq>monthly</changefreq>
132+
</url>
128133
</urlset>

0 commit comments

Comments
 (0)