Coder Social home page Coder Social logo

dlmcdonald / unittestgenerator Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 215 KB

Visual studio for Mac extension to generate unit tests from a method

License: MIT License

C# 100.00%
visual-studio-for-mac visual-studio-for-mac-extension unittest xunit nunit

unittestgenerator's Introduction

UnitTestGenerator for Visual Studio for Mac

Visual studio for Mac extension to generate NUnit unit tests from any method

Example

About

This extension was created to facilitate the creation of unit tests (Currently in the context of Xamarin.Forms). Currently, this extension only supports generation of NUnit tests and uses Moq to create mock items.

Installation

  • Download the latest mpack file from the Releases page
  • Open Extensions from the Visual Studio Menu
  • Click install from file
  • Browse to the downloaded file
  • Restart your Visual Studio for Mac

Usage

  • Right click on a method and hit "Generate Unit Test" at the bottom of the Context Menu
    • If the method is private, this option will be disabled
    • If you have not used this extension before in this project, it will prompt you to select your UnitTest project. It will then generate a Solution folder and add a json config file
  • A UnitTest class will be generated with the format <MethodName>Should.cs
    • A default SetUp method will also be generated
  • A dialog will appear, prompting you to supply the test name
  • Once you confirm the test name, the unit test method will be generated
  • The following items will be generated, based on the signature of the method:
    • expected variable based on the return type of the method (if applicable)
    • a variable for each parameter of the method with a default value based on the type of the parameter
    • Mock objects for all constructor parameters
    • Constructor initialization
    • result variable assigned to the method call
    • A default assert
    • All the using statements based on the classes used in your method and constructor

unittestgenerator's People

Contributors

dependabot[bot] avatar dlmcdonald avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

unittestgenerator's Issues

Non-interface types need to be instantiated instead of mocked

When generating a unit test that has a non-interface type in the constructor will generate code that is incorrect.

For example:

public class TestClass
{
    public TestClass(int foo)
    {
    }
}

When creating the test for this, the following will be generated:

var foo = new Mock<int>();
var vm = new TestClass(foo.Object);

this code will not compile.
We should rather use Mocks for interface types and instantiate the concrete types:

var foo = default(int);
var vm = new TestClass(foo);

Add error handling

Add error handling to project

  • User errors to be handled with an error dialog
  • Informational errors to be displayed to a VS log

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.