Programming Tips 💡
51.7K subscribers
67 photos
10 videos
30 files
354 links
Programming & AI:
Tips 💡
Articles 📕
Resources 👾
Design Patterns 💎
Software Principles

🇳🇱 Contact: @MoienTajik

🎯 Buy ads: https://telega.io/c/ProgrammingTip
Download Telegram
What is Unit Testing & Why You Need to Lean It ⁉️

Unit testing is the practice of writing code to test your code and then run those tests in an automated fashion.

🔹🔸🔹🔸

Here is an example. 👨🏻‍💻

Imagine you have this function somewhere in your code.
It’s a basic calculate function that takes an input and depending on some conditions, it returns different values.

public float CalculateTax(int input) 
{
if (x) return ...;
if (y) return ...;
return ...;
}


If you want to test this function manually :

1️⃣ You have to run your application
2️⃣ Perhaps you have to login
3️⃣ Maybe do a few clicks here
4️⃣ There to get to a page where this function is used.
5️⃣ You have to fill out a form
6️⃣ Submit it
7️⃣ Verify if this function returned the right result.

And then you have to repeat all these steps, each time using different values in your form. 🤦🏻‍♂️

🔸🔹🔸🔹

Manual testing is expensive 💸

As you can see, this is very time-consuming. ⌛️

This workflow to test this function may take several minutes every time❗️

Now to make matters worse, this is not the only function in your application. 🌍

In a real application, you have tens or hundreds of functions like this ❗️

As your application grows in size and complexity, the time required to manually test all the different bits and pieces increases exponentially.

So, that’s why we use Automated Testing. ♻️

🔺🔹🔺🔹

https://t.iss.one/pgimg/24

[ Full Article ] : https://bit.do/utdd


#CleanCode #UnitTest #TDD
@ProgrammingTip
Mocking objects with Moq and XUnit in .NET Core 👾

This article explains the step by step process that needed to Moq an object in .NET Core ⚜️

Mocking objects comes in handy when unit testing data store, where a Database can be mocked so that no data is added or modified in Database while unit testing source code. ♻️

https://t.iss.one/pgimg/32

[ Tutorial ] : https://bit.do/moqx


#UnitTest #Mocking #XUnit #Moq
@ProgrammingTip
Write tests,
Not too many,
Mostly integration.


A while back, Guillermo Rauch‏ ( Creator of Socket.io ) tweeted something profound :

Write tests. Not too many. Mostly integration.💎 


This is deep, albeit short, so let’s dive in. 🌀

https://t.iss.one/pgimg/62

[ Article ] : https://bit.do/iut


#UnitTest
@ProgrammingTip
WireMock.NET 😮

WireMock.NET is a .NET library for stubbing and mocking HTTP services. With WireMock.NET, you can define the expected responses for particular requests, and the library will intercept and manage those requests for you. ✔️

This allows for easy testing of the code that makes HTTP requests, without having to rely on the actual external service being available and without hacking HttpClient. 🆒

Sample code snippet:

[Test]
public async Task sample_WireMock_usage()
{
// Setup WireMock.Net server
using var wireMock = WireMockServer.StartWithAdminInterface(port: 1080, ssl: false);

// Setup WebApplicationFactory
await using var appFactory = new WebApplicationFactory<Program>().WithWebHostBuilder(builder =>
{
builder.ConfigureAppConfiguration(configurationBuilder =>
{
// Override downstream service addresses pointing to WireMock address
configurationBuilder.AddInMemoryCollection(new Dictionary<string, string>
{
["ExternalServices:WeatherService"] = "https://localhost:1080"
});
});
});

// Prepare stub for outgoing request
wireMock
.Given(
Request.Create()
.WithPath("/api/v1.0/weather")
.WithParam("lat", "10.99")
.WithParam("lon", "44.34")
.UsingGet()
)
.RespondWith(
Response.Create()
.WithStatusCode(200)
.WithHeader("Content-Type", "application/json; charset=utf-8")
.WithBodyAsJson(new
{
temp = 298.48,
feels_like = 298.74,
temp_min = 297.56,
temp_max = 300.05,
pressure = 1015,
humidity = 64
})
);

// Automate tested app
}


[ Blog ] : https://cezarypiatek.github.io/post/mocking-outgoing-http-requests-p1

〰️〰️〰️〰️〰️〰️
#UnitTest #DotNet #CSharp
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
A Structured Roadmap to Master Software Testing for Developers 🚀

Struggling to navigate the world of testing? 💭
I’ve compiled a comprehensive roadmap to help developers learn testing concepts systematically—whether you're a beginner or looking to fill gaps in your knowledge.

🔍 What’s Inside?
Core Testing Concepts (White/Gray/Black Box)
Test Design (Equivalence Partitioning, Boundary Analysis, etc.)
Naming Standards
Patterns (AAA, Four-Phase, BDD with Gherkin)
Test Types (Unit, Integration, E2E, Performance, etc.)
Tools & Frameworks (xUnit, Playwright, K6, AutoFixture, etc.)
Best Practices (Clean Test Code, Test Smells, Coverage)
Static Analysis & CI/CD Integration


📌 Highlights
Self-assessment friendly → Track your progress.

Language-agnostic → Examples in .NET, JS, Python, PHP.

Practical focus → From TDD/BDD to CI/CD pipelines.


[GitHub] : https://github.com/hasanxdev/Test-Roadmap-For-Developers

〰️〰️〰️〰️〰️〰️

#Test #Roadmap #UnitTest #IntegrationTest

@ProgrammingTip