Code Monkey home page Code Monkey logo

testassist's Introduction


GitHub Pull Requests welcome

About

Welcome to the TestAssist NuGet package!

This project is not yet complete and is not suitable for commercial use.

Purpose

The TestAssist package aims to streamline and enhance the process of writing unit tests in C#. It provides a collection of helpful utilities and extensions designed to simplify common tasks encountered during unit testing.

Problem it Solves

Writing effective unit tests often involves repetitive tasks such as creating mock objects, asserting certain conditions, or generating test data. TestAssist addresses these challenges by offering a set of ready-to-use functionalities that save time and effort for developers.

Key Features

  • Mocking Helpers: Simplifies the creation of mock objects using popular mocking frameworks.
  • Assertion Extensions: Provides additional assertion methods to cover common scenarios not included in standard testing libraries.
  • Utility Classes: Offers various utility classes that assist in setting up tests, handling exceptions, and managing test environments.

Benefits

This package improves the lives of developers by:

  • Increasing Productivity: Reduces boilerplate code and speeds up the creation of robust unit tests.
  • Enhancing Test Coverage: Facilitates testing of edge cases and complex scenarios through efficient data generation and mocking.
  • Improving Code Quality: Encourages best practices in unit testing by providing tools that promote clear, concise, and maintainable tests.

Built With

  • .NET 8

Getting Started

Installation

Add the TestAssist NuGet package to your project. You can do this via the NuGet Package Manager or the Package Manager Console:

dotnet add package TestAssist

Usage

The TestAssist package includes useful methods to help you create mock data and mock DbContext instances with ease. These methods uses MockQueryable.Moq, Reflection, and Expression to simplify testing of DbContext.

Mocking Data

The MockData method allows you to create a mock DbSet from a collection of entities. This is particularly useful when you need to simulate a database table in your unit tests.

Mocking DbContext

The MockDbContext method helps you create a mock DbContext by setting up multiple mock DbSet instances. This is useful when you need to mock a context that includes several tables.

Example:

// Sample DbContext
public class MyDbContext : DbContext {
    public virtual DbSet<User> Users { get; set; }
    public virtual DbSet<Order> Orders { get; set; }
}

public void Example_MockDbContext() {
    // Create lists of sample data
    var users = new List<User> {
        new User { Id = 1, Name = "Alice" },
        new User { Id = 2, Name = "Bob" }
    };

    var orders = new List<Order> {
        new Order { Id = 1, UserId = 1 },
        new Order { Id = 2, UserId = 2 }
    };

    // Create mock DbSets
    var mockUserDbSet = users.MockData();
    var mockOrderDbSet = orders.MockData();

    // Use the MockDbContext method to create a mock DbContext
    // This extension uses reflections to setup `mockContext` with the given data
    var mockContext = MockExtensions.MockDbContext<MyDbContext>(mockUserDbSet, mockOrderDbSet);

    // Now you can use the mockContext in your tests

}

By using these methods, you can efficiently create mock data and DbContext instances, allowing you to write robust unit tests for your data access code without relying on an actual database.

Roadmap

See the open issues for a list of proposed features (and known issues).

Support

Reach out to the maintainer at one of the following places:

FAQ

Is this project complete?

No. This is a personal project and will probably be completed over time.

Contributing

First off, thanks for taking the time to contribute! Contributions are what make the free/open-source community such an amazing place to learn, inspire, and create. Any contributions you make will benefit everybody else and are greatly appreciated.

Please read our contribution guidelines, and thank you for being involved!

Authors & contributors

The original setup of this repository is by HamidMolareza.

For a full list of all authors and contributors, see the contributors page.

Security

TestAssist follows good practices of security, but 100% security cannot be assured. TestAssist is provided "as is" without any warranty.

For more information and to report security issues, please refer to our security documentation.

License

This project is licensed under the GPLv3.

See LICENSE for more information.

testassist's People

Contributors

hamidmolareza avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.