sp4ceman
Well-Known Member
- Joined
- Jul 11, 2011
- Messages
- 418
- Reaction score
- 0
hey there, as you guys know i'm working on that devscore site. (if you don't know then to www.dev-score.com or search my other threads). well one of the things i have been trying to do is maintain testability as much as possible, and while i know tdd fairly well, i feel as though something is missing. i have messed around with cucumber in node and i really liked it but had no clue if you could do anything like that in visual studio.
then i found specflow and its pretty awesome. so i thought i would try and take some of specflows awesome features and just see if i could get some gain out of it. which i really did.
in devscore, im trying to keep my mvc controllers as thin as possible. so i have "modules" (i call them) which are essentially bits of logic abstracted so that you can test them. my views speak to controllers, my controllers speak only to modules. what im currenty working on is the ability for a company to log into the site and see a "dashboard". right now their dashboard will display their company name, have the company id, and will show them their average score in each of the categories that people can review.
so i created a "myCompanyModule", and it has a single method called "getMyCompanyDash" and that takes in one argument the company id. thats all i knew about the module and the method before opening my specflow spec and starting to write stuff down.
now i know im not doing this true BDD style, im really unit testing a single method instead of behaviours and high level things. im doing TDD, so i wrote my spec, generated my test methods, watched them fail and then made them pass. so its still the red / green / refactor pattern from tdd in terms of how i write things.
the spec i ended up with (is prolly all wrong) was this ::
and the resulting models, module and tests can be found here :
https://gist.github.com/anonymous/3c6e035275c408a83fd0
for those of you unfamiliar with what this is doing, my spec up there in english is actually my test that is run. specflow looks at the sentence "Given an empty storage" and then runs the c# code i wrote that spins up an empty storage. each sentence there is a bit of code. which you can see in the tests section of the gist.
if anyone is familiar with TDD or BDD and has any feedback or questions please feel free. like i said, i know im doing it wrong, its not BDD. im just using specflow to generate cool englishy sentences and make my testing a lot easier. and it worked really well.
i'm using MOQ to create mocks of my entity framework stuff and the code isn't complete as im obviously referencing methods and classes that aren't shown here.
then i found specflow and its pretty awesome. so i thought i would try and take some of specflows awesome features and just see if i could get some gain out of it. which i really did.
in devscore, im trying to keep my mvc controllers as thin as possible. so i have "modules" (i call them) which are essentially bits of logic abstracted so that you can test them. my views speak to controllers, my controllers speak only to modules. what im currenty working on is the ability for a company to log into the site and see a "dashboard". right now their dashboard will display their company name, have the company id, and will show them their average score in each of the categories that people can review.
so i created a "myCompanyModule", and it has a single method called "getMyCompanyDash" and that takes in one argument the company id. thats all i knew about the module and the method before opening my specflow spec and starting to write stuff down.
now i know im not doing this true BDD style, im really unit testing a single method instead of behaviours and high level things. im doing TDD, so i wrote my spec, generated my test methods, watched them fail and then made them pass. so its still the red / green / refactor pattern from tdd in terms of how i write things.
the spec i ended up with (is prolly all wrong) was this ::
Feature: myCompanyModule.getMyCompanyDash
In order to view my companys overview
As a company subscriber
I want to call myCompanyModule.getMyCompanyDash and generate the dashboard
@mytag
Scenario: call myCompanyModule.getMyCompanyDash and passing a companyID that doesnt match existing company
Given an empty storage
And a new myCompanyModule
When companyID doesnt match existing company
And i getMyCompanyDash with companyID
Then the result should be null
Scenario: call myCompanyModule.getMyCompanyDash and passing a companyID that matches existing company with no reviews
Given a storage with existing company
And a storage with no reviews for company
And a new myCompanyModule
When companyID matches existing company
And i getMyCompanyDash with companyID
Then the result should not be null
And the results companyName should not be null or empty
And the results companyName should equal the name of the company who's id matches companyID
And the results hasReviews should be false
And the results categories should be empty
Scenario: call myCompanyModule.getMyCompanyDash and passing a companyID that matches existing company with single review
Given a storage with existing company
And a storage with a single review for company
And a new myCompanyModule
When companyID matches existing company
And i getMyCompanyDash with companyID
Then the result should not be null
And the results companyName should not be null or empty
And the results companyName should equal the name of the company who's id matches companyID
And the results hasReviews should be true
And the results categories should not be empty
And the results categories should equal the number of categories in storage
And the results categories should calculate the average for each entry correctly
And the results categories should assign each entries category name correctly
And the results categories should assign each entries category id correctly
Scenario: call myCompanyModule.getMyCompanyDash and passing a companyID that matches existing company with multiple reviews
Given a storage with existing company
And a storage with multiple reviews for company
And a new myCompanyModule
When companyID matches existing company
And i getMyCompanyDash with companyID
Then the result should not be null
And the results companyName should not be null or empty
And the results companyName should equal the name of the company who's id matches companyID
And the results hasReviews should be true
And the results categories should not be empty
And the results categories should equal the number of categories in storage
And the results categories should calculate the average for each entry correctly
And the results categories should assign each entries category name correctly
And the results categories should assign each entries category id correctly
and the resulting models, module and tests can be found here :
https://gist.github.com/anonymous/3c6e035275c408a83fd0
for those of you unfamiliar with what this is doing, my spec up there in english is actually my test that is run. specflow looks at the sentence "Given an empty storage" and then runs the c# code i wrote that spins up an empty storage. each sentence there is a bit of code. which you can see in the tests section of the gist.
if anyone is familiar with TDD or BDD and has any feedback or questions please feel free. like i said, i know im doing it wrong, its not BDD. im just using specflow to generate cool englishy sentences and make my testing a lot easier. and it worked really well.
i'm using MOQ to create mocks of my entity framework stuff and the code isn't complete as im obviously referencing methods and classes that aren't shown here.
Last edited: