SShortSingh.
0
ProgrammingDEV Community ·

Combining Object Mother Pattern with AutoFixture for Cleaner Unit Tests

A software development tutorial published on DEV Community demonstrates how to combine the Object Mother design pattern with the AutoFixture library in C#. The Object Mother pattern centralizes test object creation, improving test readability and semantic clarity. AutoFixture complements this by automatically generating random test data, reducing manual setup effort. The article walks through a practical example using a User class and age-based access logic, showing how a UserMother class leverages AutoFixture's Build API to produce meaningful test objects. The combination allows developers to maintain expressive, well-organized unit tests without sacrificing flexibility in data generation.

0
ProgrammingDEV Community ·

How to Use AutoFixture with Immutable Entities in C# Unit Tests

AutoFixture is a popular .NET library used to generate test data for unit tests, but it behaves differently when working with immutable entities. While AutoFixture can successfully instantiate an immutable object using its factory method, it throws an unhandled exception when attempting to customize read-only properties via the Build().With() syntax. This issue surfaces when developers refactor their domain entities to be immutable — a recommended practice — and then find their existing AutoFixture-based tests breaking. The article, originally published on carlosvigueras.es, demonstrates the problem using an immutable User entity with a private constructor and a static Create method. A follow-up solution to resolve this incompatibility is promised in the same post.

0
ProgrammingDEV Community ·

AutoFixture: Open-Source .NET Library That Automates Test Object Creation

AutoFixture is an open-source .NET library available via NuGet that simplifies unit test setup by automatically generating objects with random data. It is designed to minimize the 'Arrange' phase of unit tests, allowing developers to focus on what is being tested rather than how test scenarios are configured. The library is particularly useful when dealing with complex objects, eliminating the need to manually assign values field by field. It also supports customized field values when random data is not sufficient for a specific test case. The article demonstrates its use through a practical example involving a User class with multiple properties tested against a Home access method.

0
ProgrammingDEV Community ·

Builder Pattern Explained as a Test Data Alternative to Object Mother

A software developer published a tutorial on the Builder design pattern, presenting it as an alternative to Martin Fowler's Object Mother pattern for creating test data. The Builder pattern is a creational design pattern used to construct complex objects, applicable in both production code and test suites. The author notes that its use in testing is a matter of preference, with both proponents and critics in the developer community. Using a C# example with User and Home classes, the tutorial demonstrates how a UserBuilder separates data creation from test logic to improve test clarity and readability. The full example code is made available on the author's GitHub repository for reference.

0
ProgrammingDEV Community ·

Data Clumps: The Code Smell That Signals Poor Program Structure

Data Clumps is a well-known code smell in object-oriented programming that refers to groups of variables repeatedly passed together across multiple parts of a program. These variables are usually related and carry a shared meaning, which is why they tend to travel together rather than being properly encapsulated. The presence of Data Clumps often signals deeper issues in software design or implementation that can hinder future scalability and maintainability. The recommended fix is refactoring: grouping related variables into dedicated classes, such as separating user data and booking date ranges into their own objects. Cleaner, better-structured code is easier to understand, modify, and scale over time.

0
ProgrammingDEV Community ·

Rule of Three: When and Why to Refactor Your Code, Explained Simply

The Rule of Three is a code refactoring principle popularized by Martin Fowler that guides developers on when to clean up repetitive code. It states that the first time you write something, just do it; the second time you write something similar, note the repetition but proceed anyway; by the third time, refactoring should begin. Refactoring improves code readability, maintainability, and benefits both the original developer and future contributors. The principle applies whether you are adding a new feature, fixing a bug, or conducting a code review. A simple C# example using Cat, Bird, and Snake classes illustrates how repeated code can be consolidated into a shared Animal base class through inheritance.

0
ProgrammingDEV Community ·

Object Mother Pattern: A Cleaner Way to Manage Test Data in .NET

The Object Mother pattern, introduced by Martin Fowler in 2006, is a class used in testing to centralise the creation of sample objects shared across multiple test suites. Unlike the Builder pattern, Object Mother avoids adding unnecessary complexity or logic to test code, which is a key concern since tests themselves should remain as logic-free as possible. By centralising test data, developers eliminate repetitive object instantiation scattered across different test files. A practical .NET and NUnit example illustrates the pattern using a user-age-based discount application with four distinct user categories. The author argues that while both patterns have their advocates, Object Mother offers a simpler and more maintainable approach to test data management.

0
ProgrammingDEV Community ·

How AI Agents Discover Unknown Marketplaces Using a Single Bootstrap URL

A software broker system has been built to introduce two AI agents to each other and facilitate negotiations, with neither agent preconfigured for the marketplace beforehand. The entire discovery process bootstraps from a single URL pointing to an Agent Card, a machine-readable document that identifies the service, its protocol version, available skills, and authentication requirements. The Agent Card is cryptographically signed using EdDSA to establish a root of trust, allowing consumers to verify the document has not been tampered with in transit. Rather than listing all marketplace functions, the card intentionally exposes only one skill — onboarding — since new agents have no account or credentials to access any other feature. This design principle ensures every element on the card is immediately actionable by the reader, preventing agents from getting stuck calling methods they are not yet eligible to use.

0
ProgrammingDEV Community ·

Developer shares personal takeaways from applying Object Calisthenics in production code

A software developer has published a concluding reflection on Object Calisthenics, a set of nine programming exercises designed to reinforce good object-oriented design principles. The author describes how they gradually internalized the rules by practicing through coding katas before applying them to real production code. According to the developer, the exercises consistently promote more readable, understandable, and maintainable code by reinforcing encapsulation and the single responsibility principle. The author recommends the Kata-Log-Rocks website as a resource for developers looking to practice these techniques alongside TDD and code smell detection. The post closes with a note that the rules should be applied with common sense rather than rigidly, and signals that upcoming articles will focus on Test-Driven Development.

0
IndiaTimes of India ·

Father Spends $800K on Land to Build Tiny-Home Community for Disabled Adults

Dave Curro is developing Forest Grove, a purpose-built community for adults with special needs, inspired by his son Bret. The project will feature 20 tiny homes alongside a community center offering essential support services. Curro personally invested $800,000 to secure the land for the initiative. A recent fundraising festival drew strong community backing for the project. Forest Grove aims to address a significant gap in affordable, suitable housing for disabled adults.

0
IndiaTimes of India ·

142-Year-Old Seed Experiment Yields Viable Plants, Set to Continue Till 2100

A seed dormancy experiment launched by botanist William James Beal in 1879 continues to yield remarkable results over a century later. In 2021, researchers unearthed seeds from the experiment and found them still viable after 142 years. DNA analysis also revealed the presence of a previously undetected hybrid moth mullein among the samples, adding an unexpected dimension to the study. The findings are expected to inform land restoration practices and support efforts to manage invasive plant species. The long-running experiment is designed to continue until 2100, underscoring science's capacity for multigenerational inquiry.

0
IndiaNDTV ·

Drunk Man Kills Wife in UP After She Refused to Skip Dance Class to Cook

A 41-year-old man named Krishna Lal Yadav allegedly killed his wife Yamini Krishna Lal Yadav in a fit of rage. The incident was triggered after Yamini refused to cook, as she wanted to attend a dance class. The accused was reportedly drunk at the time of the attack. The couple had two young children together. Authorities have identified both the victim and the accused in connection with the case.

0
IndiaTimes of India ·

Raina warns IPL impact player rule tilts game too far in batters' favour

Former Indian cricketer Suresh Raina has raised concerns about the IPL's impact player rule, claiming it disproportionately advantages batters and drives up scores. He argued that the rule leaves bowlers with little room to compete on equal terms. Raina also advised Indian cricketers to avoid participating in overseas T20 leagues, stating that the IPL has grown into a world-class competition in its own right. He further observed that the standard of foreign T20 leagues has visibly declined in recent years compared to their earlier quality.

← NewerPage 800 of 4481Older →