Convert C# unit test names to English (testdox style)

青春壹個敷衍的年華 提交于 2019-12-06 08:23:59

问题


I have a whole bunch of unit tests written in MbUnit and I would like to generate plain English sentences from test names. The concept is introduced here:

http://dannorth.net/introducing-bdd

This is from the article:

public class CustomerLookupTest extends TestCase {
    testFindsCustomerById() {
        ...
    }
    testFailsForDuplicateCustomers() {
        ...
    }
    ...
}

renders something like this:

CustomerLookup
- finds customer by id
- fails for duplicate customers
- ...

Unfortunately the tool quoted in the above article (testdox) is Java based. Is there one for .NET?

Sounds like this would be something pretty simple to write, but I simply don't have the bandwidth and want to use something already written.

EDIT: Just to clarify the question. I am looking at something that can whiz through existing tests and convert CamelCase function names into sentences. Seems like a perfect job for some sort of Gallio plugin.

So far I somehow found SpecUnit and Jay has suggested BDDDoc. Both of those are behaviour verification frameworks that will require a significant rewrite of the exisitng tests. Our team has made the decision to go with SpecFlow as a main BDD framework and what I was trying to achieve is to generate a report of the existing tests to see how well it fits the BDD approach.


回答1:


There is a TestDox for .NET It seems fairly recent (2010).




回答2:


For a presentation last year I have created a small BDD unit testing helper that displays the method names being executed in normal English. The string magic part of it is quite thin so you can surely extract it from it.

Here is my post with the link to the download: http://gasparnagy.blogspot.com/2009/10/devcamp09-behavior-driven-development.html




回答3:


Have a look at developwithpassion.bdd and bdddoc, developed by JP Boodhoo.

His original blog post on it is here: http://blog.jpboodhoo.com/BDDDoc.aspx

You can find the code on github here: http://github.com/developwithpassion/developwithpassion.bdd

I use his testing framework, and BDDDoc generates plain English HTML reports that even show whether the tests pass or not, by tying into the mbUnit and Gallio reports.

The format, though is that each fixture has a Concern attribute for bdddoc to pick up and group the specs.

My fixtures are named like public class When_the_sound_system_is_off... and my assertions are delegates of type it (from the framework), so they read it should_not_be_spinning_a_compact_disc..., it should_emit_no_sound..., etc.

BDDDoc works off this underscorish syntax, but I think since you are already using mbUnit, you can probably extract the interesting bits of code and tailor it to your needs.




回答4:


StoryQ has quite a good workflow for converting existing unit tests to BDD style - I know that's not directly answering your question but might be worth checking out...




回答5:


This C# test framework also does a very good job of converting method to English

UBADDAS - User Behaviour and Domain Driven Acceptance Stories

found here - http://kernowcode.github.io/UBADDAS/

Converts this ...

[Test]
public void IWantToRegisterANewUser()
{
  ICustomer customer = new Customer();

  SoThat(MyBusinessValue.IncreaseCustomerBase)
    .As(new User())
    .Given(customer.Register)
    .When(customer.Confirm_Registration)
    .Then(customer.Login);
}

to this ...

I want to register a new user
  So that Increase customer base
       As user
    Given Register customer
     When Confirm customer registration
     Then Login customer


来源:https://stackoverflow.com/questions/2430036/convert-c-sharp-unit-test-names-to-english-testdox-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!