Giter VIP home page Giter VIP logo

unitverse's Introduction

Visual Studio Marketplace Last Updated Visual Studio Marketplace Last Updated

Introduction ๐Ÿ‘€

Unitverse is an extension for Visual Studio 2019 and Visual Studio 2022 that generates tests for classes written in C#. There is a bunch of information about the extension in the documentation.

Documentation ๐Ÿ“–

The best way to view the documentation is to visit the documentation on GitHub pages. Alternatively, you can view the documentation direct from the repository using the links to sections below.

Documentation Sections

  • Introduction - introduction to the unit test generator project & basic info.
  • Getting started - covering basic usage and how to start generating tests.
  • Features - covers the features offered by Unitverse along with in-depth descriptions.
  • Configuration - covering the configuration options available, as well as details on how to configure the extension through source code.
  • Examples - presents a selection of sample scenarios showing the source code and the generated tests.
  • Templating - information about the templating functionality in Unitverse.

Contributing โœ‹

Any contributions are welcome. Code. Feedback on what you like or what could be better. Please feel free to fork the repo and make changes, the license is MIT so you're pretty much free to do whatever you like. For more information, please see the contributing section.

Support ๐Ÿค

If you'd like to support the project but you don't want to contribute code - a really good way to help is spread the word. There isn't a donation or financial option because honestly I don't need donations. I am, however, rubbish at 'marketing'. So any help there would be greatly appreciated! Whether it's a blog post, a marketplace review or just telling some folks at the office - every little helps.

History ๐Ÿ“…

Unitverse was originally the SentryOne Unit Test Generator, and was written as part of an 'innovation sprint' where we wanted to write something that made our work more efficient. Unitverse is a fork of that project, and is not affiliated with any particular company. The license has also changed from Apache to MIT - please see the license update notice for details of this change. Thanks to all the original members of the team, as well as people who have submitted code/issues since then.

unitverse's People

Contributors

304notmodified avatar adathedev avatar esmithsentryone avatar jwelch-s1 avatar kilazur avatar mattwhitfield avatar mazzelfassel avatar radeilic avatar thalter avatar will-atherton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

unitverse's Issues

Rename the repo to Unitverse

I was a bit confused that the extenion is named Unitverse and this repo unittestgenerator.

Proposal: rename this repo. Github add a redirect (also for the git url), so the rename is safe - all old hyperlinks and clone urls will still work!

Of course you could add some tags if you think this repo is hard to find with the new name

Missing: Create in temporary folder

In Version 0.105 it was possible to generate tests to a temporary directory - with version 0.107 it forces me to choose a project. So I always have to go there and delete the file afterwards.

The usage of temporary generated files helps a lot in some use cases

TestProjectNaming in options window does not match settings

Hi again :)

Version: 0.104.0.0

My .unitTestGeneratorConfig has the following lines:

TestProjectNaming={0}.Test
TestFileNaming={0}Test
TestTypeNaming={0}Test

But in the settings window it shows the plural form:

image

And when I export, it will override these lines with Tests

Issue generating in VS2022

When generating in VS2022 ->

Exception raised
System.MissingMethodException: Method not found: 'EnvDTE.Solution EnvDTE._DTE.get_Solution()'.

at Unitverse.Helper.ProjectItemModel.get_TargetProject()

at Unitverse.Commands.GenerateTestForSymbolCommand.<>c__DisplayClass13_0.b__0() in D:\a\unittestgenerator\unittestgenerator\src\Unitverse\Commands\GenerateTestForSymbolCommand.cs:line 214

at Unitverse.Helper.Attempt.Action(Action action, IUnitTestGeneratorPackage package) in D:\a\unittestgenerator\unittestgenerator\src\Unitverse\Helper\Attempt.cs:line 21

See https://developercommunity.visualstudio.com/t/dte-events-not-working-in-vs2022/1455126
Also see https://cezarypiatek.github.io/post/migrate-vsix-to-vs2022/

Feature Request: Support test generation for items marked with "internal" access.

I'd like to suggest a new feature:
Adding an option to define the scope of the methods/etc. selected for test generation.

  • public only
  • public and internal
  • [public, internal and private] <-- maybe

I believe, based on my use, that only public items are selected for test generation. I also know that not everyone believes that non-public methods, should be included in units tests.

Adding the feature doesn't limit these beliefs, but does open up the use of Unitverse extension to more user scenarios.

Thanks for your consideration.

Unable to select the project to which the test will be added

When I click "Generate test for method 'SomeMethod'..." I want to select project to which the test will be added, like is in NUnit Visual Studio Test Generator.

Some methods I test in the project with unit tests, and some methods I test with higher correlations (e.g. with database connection), than project has a different name.

Also, our project names have evolved over the years, so we have many patterns. Some projects I could refactor, but not all.

Do you have any ideas for my case?

Set page titles and favicon for GitHub pages

Set page titles and favicon for GitHub pages - ideally title should be

Unitverse | Page Title

But not Unitverse | Unitverse for the home page

Ideally we could add a favicon too

Add interface tests for IEquatable<T>

We want to emit interface tests for IEquatable

This also needs to cover the case where T is not the type on which the interface is declared.

I.e. we need to support all of these:

SomeType : IEquatable<SomeType>
SomeType : IEquatable<SomeOtherType>
SomeType : IEquatable<SomeType>, IEquatable<SomeOtherType>

Allow multiple patterns for unit test projects

Currently you can only enter one pattern for project naming conventions (e.g. {0}.Tests).

It would be useful to support multiple patterns, so solutions without a strong naming convention can be supported.

Add ability to generate new tests only

When right clicking a class symbol and selecting 'generate tests' it will complain if any tests exist and ask for regeneration to happen. It could be modified such that any new tests are added to the test class in a non-destructive way.

This could be the default behaviour for generate tests, or we could add a new command 'generate new tests only'.

[Feature] Support Moq.AutoMock

Would be cool if this generator detects and supports Moq.AutoMock

e.g.

var mocker = new AutoMocker();
_logger = mocker.GetMock<ILogger<MyClass>>();
_sut = mocker.CreateInstance<MyClass>();

Variable naming options

Hey, love the extension!

One thing I would like to see is an option to name variables without the leading underscore.

And another would for the testClass to be called sut (System Under Test)

UnitVerse uses first class in file, not the class I selected

Hi

Often if my extension methods require some specific classes, I will just put them in the same file

image

However then when I try to generate the extension method tests, it tries to generate tests for those classes which I defined earlier in the same file

Generate mock configuration calls

This one is a bigger one - but...

Given a class that takes a constructor dependency and stores it in a field _field - then whenever a method call or property get is made to _field within the context of the method - detect that call and automatically configure the mock with default values.

Would just save a bunch of typing.

Allow navigation to tests by type name

Sometimes when refactoring the test class file might be incorrectly named. If performance allows it, we should be able to navigate to the test type using the type name.

Expand the contibuting docs

Probably worth explaining a few things in the code base

  • How the tests are mostly driven from the test resources and then each test class is generated 18 times (one for each framework, with and without fluent assertions)
  • How the general ethos is to care less about the output being really specific and more about producing something that compiles (within reason)
  • How the example generator works, and how the build protection works
  • Areas that could do with some tidying up
  • General code map

Delegates with out parameter not generated correctly

Hi again :)

Input:

public delegate void ExpandConstantDelegate(string input, out string output);
public static void RegisterExpandConstantCallback(ExpandConstantDelegate callback)
{
}

Generated test

 [Test]
        public static void CanCallRegisterExpandConstantCallback()
        {
            // Arrange
            Exports.ExpandConstantDelegate callback = (x, y) => { };
                                                          ^ Should have out keyword   
            // Act
            Exports.RegisterExpandConstantCallback(callback);
            
            // Assert
            Assert.Fail("Create or modify test");
        }

Easy to manually fix, just thought I would report it

usings above namespace

Maybe this is really opionated,

But the using in the default class template of Visual studio is above the namespace

Current result:

namespace MyNameSpace
{
    using System;
    using Xunit;
    using FluentAssertions;

    public class MyClassTests
    {

expected/desired:

using System;
using Xunit;
using FluentAssertions;

namespace MyNameSpace
{
    public class MyClassTests
    {

For example, the new class template in VS2022 generates:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyNameSpace
{
    internal class Class1
    {
    }
}

Work out how to handle newer versions of Roslyn

If we use Roslyn 4 in the core library, we could support things in C# 10 (file scoped namespaces being one).

The boilerplate generator does this by referencing an older version and using reflection. This might work but given that this extension emits code by building Roslyn trees it might make it tricky.

This could potentially lead to a version of Unitverse that could be compiled for VS2017.

Option to disable null tests

Hi again :) Really enjoying this extension so far

I would like to see an option to disable the auto generated tests which check the behavior with null types. Our code base never has any nulls, so we also don't guard against them, and also are not interested in testing for them

Also an option to disable the CanConstruct test

Support internal classes

Hello again :)

Very often I expose my internals to my tests, and test my internal classes. Currently this extension requires class to be public.

Emit better default values for Func<T> and Action<T>

For Func, currently default(Func) is emitted. It would be better if () => T was emitted, and we use the assignment value helper to generate a value for T.

For Action, we should emit () => { }

For the parameters, we should emit:

0 parameters: ()
1 parameter: x
2/3 parameters: (x, y) or (x, y, z)
4+ parameters: (a, b, c, d), (a, b, c, d, e) etc

"out" modifiers are not emitted on generated abstract class method output parameters

Example:

public abstract class Foo
{
    protected abstract bool TryMe(string bar, out string foobar);

    public void DoSomething()
    {
        // Magic
    }
}

When you generate tests for this, it will generated an implementation like below - note the "out" parameter modifier is missing:

public class TestFoo : Foo
{
    protected override bool TryMe(string bar, string foobar)
    {
        return default(bool);
    }
}

Some way to export settings within the project?

Hi, so now the extension can be configured, it works great.

However each team member would have to configure it to match the project style. It would be amazing if the config could be exported, so I could add it to the .git repository, and then anyone using the project would automatically get the same settings

I would like to see a .unitverse file which can be saved to the repository

[Feature] support The Arrange, Act, and Assert (AAA) Pattern

Would be great if the comments for AAA are generated. (// Arrange, // Act, // Assert)

e.g.

// Arrange
var repository = Substitute.For<IClientRepository>();
var client = new Client(repository);

// Act
client.Save();

// Assert
mock.Received.SomeMethod();

Exception on Generate Tests

Anytime I try to generate tests, whether it be at a project level, class level, or method level, I get this exception.


Microsoft Visual Studio

Unitverse

Exception raised
System.MissingMethodException: Method not found: 'EnvDTE.Solution EnvDTE._DTE.get_Solution()'.

at Unitverse.Helper.ProjectItemModel.get_TargetProject()

at Unitverse.Commands.GenerateUnitTestsCommand.<>c__DisplayClass12_0.b__0() in D:\a\unittestgenerator\unittestgenerator\src\Unitverse\Commands\GenerateUnitTestsCommand.cs:line 135

at Unitverse.Helper.Attempt.Action(Action action, IUnitTestGeneratorPackage package) in D:\a\unittestgenerator\unittestgenerator\src\Unitverse\Helper\Attempt.cs:line 21

OK

I am using VS2022 and the extension version is 0.67.0.0

Code tidy-up

A few things in the code need tidying up - some usings no longer required, some things could be extracted to constants (name of options files, extension GUID).

[bug?] directives outside namespace will remove current usings

Given this test class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using FluentAssertions;
using Moq;
using Xunit;

namespace MyNameSpace
{
    using MyNameSpace.Domain; // Note!

    public class MyTests{ 

....

}
  1. Enable directives outside namespace. image
  2. Generate a test methode for an existing class (and with exiting tests class)

Current result

  1. Test will be added (nice!)
  2. Almost all usings are removed! (not expected)

Result:

using MyNameSpace.Domain; 
// Missing usings

namespace MyNameSpace
{
        public class MyTests{ 

        [Fact]
        public void CanCall() {... }


}

Note:

  • when missing using MyNameSpace.Domain; // Note!, we have as a result 0 usings
  • this isn't an issue when directives outside is false

Exception when try to generate test or go to test

Environment: Visual Studio 2022 (Version 17.2.0 Preview 1.0)
Unitverse: 0.113.0.0

When I Click "Generate test for method ...", I get a MessageBox with the content:

Unitverse

Exception raised
System.NotImplementedException: Nie zaimplementowano. (Exception from HRESULT: 0x80004001 (E_NOTIMPL))

   at EnvDTE.Project.get_FileName()
   at Unitverse.Helper.VsProjectHelper.<FindProjects>d__5.MoveNext() in D:\a\Unitverse\Unitverse\src\Unitverse\Helper\VsProjectHelper.cs:line 60
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at Unitverse.Helper.ProjectMappingFactory.CreateMappingFor(Project sourceProject, IUnitTestGeneratorOptions baseOptions, Boolean interactive, Boolean skipManuallySelectedTargetResolution) in D:\a\Unitverse\Unitverse\src\Unitverse\Helper\ProjectMappingFactory.cs:line 26
   at Unitverse.Commands.GenerateTestForSymbolCommand.<>c__DisplayClass13_0.<Execute>b__0() in D:\a\Unitverse\Unitverse\src\Unitverse\Commands\GenerateTestForSymbolCommand.cs:line 205
   at Unitverse.Helper.Attempt.Action(Action action, IUnitTestGeneratorPackage package) in D:\a\Unitverse\Unitverse\src\Unitverse\Helper\Attempt.cs:line 18

When I Click "Go to tests", I get a MessageBox with the content:

Unitverse

Exception raised
System.NotImplementedException: Nie zaimplementowano. (Exception from HRESULT: 0x80004001 (E_NOTIMPL))

   at EnvDTE.Project.get_FileName()
   at Unitverse.Helper.VsProjectHelper.<FindProjects>d__5.MoveNext() in D:\a\Unitverse\Unitverse\src\Unitverse\Helper\VsProjectHelper.cs:line 60
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at Unitverse.Helper.ProjectMappingFactory.CreateMappingFor(Project sourceProject, IUnitTestGeneratorOptions baseOptions, Boolean interactive, Boolean skipManuallySelectedTargetResolution) in D:\a\Unitverse\Unitverse\src\Unitverse\Helper\ProjectMappingFactory.cs:line 26
   at Unitverse.Helper.GoToTestsHelper.FindTestsFor(ProjectItemModel source, IUnitTestGeneratorPackage package) in D:\a\Unitverse\Unitverse\src\Unitverse\Helper\GoToTestsHelper.cs:line 14
   at Unitverse.Commands.GoToUnitTestsForSymbolCommand.<Execute>b__8_0() in D:\a\Unitverse\Unitverse\src\Unitverse\Commands\GoToUnitTestsForSymbolCommand.cs:line 107
   at Unitverse.Helper.Attempt.Action(Action action, IUnitTestGeneratorPackage package) in D:\a\Unitverse\Unitverse\src\Unitverse\Helper\Attempt.cs:line 18

Statistics collection

It would be interesting to have a 'statistics' function to track generated content

Number of lines of code generated
Number of test methods generated
Number of incomplete test methods generated (i.e. something with an Assert.Fail)
Number of complete test methods generated

Derived class may sometimes be emitted when not needed

If you

  • have a test class with a protected property
  • enable the option to emit a derived class to expose protected members (enabled by default)
  • turn off strategies that test protected members

Then the test class will be emitted using the Abstract strategy, even though the derived class isn't necessary. This requires a two-pass evaluation of strategies. First pass 'marks' members that have strategies emitted for them. Abstract strategy would then be picked only if any protected members are marked.

Documentation revamp

The documentation doesn't mention generation for abstract classes, for example. It could do with some sprucing up.

More documentation updates

Features page doesn't really work as a table - split it out
Docs don't have a link to the github repo
Contributing not linked to in the documentation sections
Contributing doesn't have a bunch of useful info - it does have code map, but nothing around expectations etc
Contributing should be added as CONTRIBUTING.md to the root of the repo
Docs don't really call out that per-member generation is a thing

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.