Auto-generation of .NET unit tests

2019-01-23 10:50发布

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?

...are there examples of using a technology like this?

...is this only good for certain types of applications, or could it be used to replace all manually written unit testing?

12条回答
男人必须洒脱
2楼-- · 2019-01-23 11:20

Parasoft .TEST has a functionality of tests generation. It uses NUnit framework for tests description and assertions evaluation.

It is possible to prepare a regression tests suite by automated generating scenarios (constructing inputs and calling tested method) and creating assertions which are based on the current code base behavior. Later, after code base under tests evolves, assertions indicates regressions or can be easily recorded again.

查看更多
Luminary・发光体
3楼-- · 2019-01-23 11:21

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

查看更多
可以哭但决不认输i
4楼-- · 2019-01-23 11:22

Selenium generates unit tests from user commands on a web page, pretty nifty.

查看更多
等我变得足够好
5楼-- · 2019-01-23 11:28

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.

查看更多
SAY GOODBYE
6楼-- · 2019-01-23 11:29

I agree with Jon. Certain types of testing, like automated fuzz testing, definitely benefit from automated generation. While you can use the facilities of a unit testing framework to accomplish this, this doesn't accomplish the goals associated with good unit test coverage.

查看更多
戒情不戒烟
7楼-- · 2019-01-23 11:31

Take a look at Pex. Its a Microsoft Research project. From the website:

Pex generates Unit Tests from hand-written Parameterized Unit Tests through Automated Exploratory Testing based on Dynamic Symbolic Execution.

查看更多
登录 后发表回答