Auto-generation of .NET unit tests

后端 未结 12 1625
故里飘歌
故里飘歌 2020-12-14 14:59

Is there such a thing as unit test generation? If so...

...does it work well?

...What are the auto generation solutions that are available for .NET?

相关标签:
12条回答
  • 2020-12-14 15:32

    There is a commercial product called AgitarOne (www.agitar.com) that automatically generates JUnit test classes.
    I haven't used it so can't comment on how useful it is, but if I was doing a Java project at the moment I would be looking at it.

    I don't know of a .net equivalent (Agitar did one announce a .net version but AFAIK it never materialised).

    0 讨论(0)
  • 2020-12-14 15:39

    GennyMcGenFace creates a unit test for each function in your class and generates objects with random words/values in each parameter.

    • Generate unit tests for each function in your class
    • Figures out valid randomly generated values for the paramater inputs and the returns statement.
    • Mockable interfaces return valid randomly generated values
    • Generate unit tests for each function in your class
    • Imports all the needed namespaces into your test class

    It helps in setting up your unit tests, especially if you have input objects with lots of parameters.

    The unit test will look something like this

    0 讨论(0)
  • 2020-12-14 15:40

    I've used NStub to stub out test for my classes. It works fairly well.

    0 讨论(0)
  • 2020-12-14 15:41

    I believe there's no point in Unit test generation, as far as TDD goes.

    You only make unit tests so that you're sure that you (as a developer) are on track w/ regards to design and specs. Once you start generating tests automatically, it loses that purpose. Sure it would probably mean 100% code coverage, but that coverage would be senseless and empty.

    Automated unit tests also mean that your strategy is test-after, which is opposite of TDD's test-before tenet. Again, TDD is not about tests.

    That being said I believe MSTest does have an automatic unit-test generation tool -- I was able to use one with VS2005.

    0 讨论(0)
  • 2020-12-14 15:41

    I know this thread is old but for the sake of all developpers, there is a good library called unit test generator:

    https://visualstudiogallery.msdn.microsoft.com/45208924-e7b0-45df-8cff-165b505a38d7

    Good dev

    0 讨论(0)
  • 2020-12-14 15:44

    I created 'ErrorUnit' and it generates MSTest or NUnit unit tests from your paused Visual Studio, or from your error logs; Mocking class variables, Method Parameters, and EF Data access so far. (http://ErrorUnit.com)

    No Unit Test generator can do everything; Unit Tests are classically separated into three parts Arrange, Act and Assert; the Arrange portion is the largest part of a unit test and it sets up all the preconditions to a test, mocking all the data that is going to be acted upon in the test, the Act portion of an Unit Test is usually one line and activates the portion of code being tested passing in that data, and finally the Assert portion of the test takes the results of the Act portion and verifies that it met expectations ( can be zero lines when just making sure there is no error).

    Unit Test generators generally can only do the 'Arrange', and 'Act' portions on unit test creation; however unit test generators generally do not write 'Assert' portions as only you know what is correct and what is incorrect for your purposes. So some manual entry/extending of Unit Tests is necessary for completeness.

    0 讨论(0)
提交回复
热议问题