My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Links

this is a bit of learning code. Feedback and patches welcome.

Primary Goal

Have a bit of help with spec/context style BDD over the typical NUnit class=spec method=rule approach.

Why Am I Building This ?

I need to be able to provide well formatted reports to business experts at my job.

Why don't I use or contribute to BDD framework X ?

I thought about it a lot, but fundamentally all the .Net ones I've seen either are A) acceptance given/when/then or they B) have in my opinion steeper learning curve than I'm comfortable throwing at junior devs. I wanted something that was more opinionated in its usage.

Do you have any samples ?

Here is a quick one more coming later.

  1. Create a class that inherits from base spec
  2. Name your spec after the object you're trying to test with spec at the end. ex: "BankAccountSpec"
  3. Create methods inside that class for each context. The method has to start with "when"
  4. Add rules with the BaseSpec's "should" method. Place the rule text and the method to execute inside the the "should" method.
  5. Compile dll
  6. Run SpecMaker.exe on the dll where the spec is.

 

namespace SpecMaker.UnitTests.SupportClasses { public class BankAccountSpec : BaseSpec { private BankAccount account; private BankAccount emptyaccount; private void refresh() { emptyaccount = new BankAccount(); account = new BankAccount(); emptyaccount.Transactions.Add(new BankTransaction() { Amount = -0.50m, Title = "Account Fee" }); } public void when_calculating_account_totals() { refresh(); should("report totals from transactios", () => { account = new BankAccount(); BankTransaction transaction1 = new BankTransaction { Amount = 1.00m, Title = "Gum" }; BankTransaction transaction2 = new BankTransaction { Amount = 2.50m, Title = "Candy Bar Purchase" }; account.Transactions.AddRange(new[] {transaction1, transaction2});

}); refresh(); should("alert user if total less than 0.0", ()=> { try { var total = emptyaccount.Total; Assert.Fail("should not be here"); } catch (AccountException) { } } ); } } }

Console Output should look something like this:
 BankAccount         when calculating account totals
          - It Should report totals from transactios - Passed
          - It Should alert user if total less Than 0.0 - Passed
 
I'll have more in a few days but this is a starting point

Powered by Google Project Hosting