How to structure my testing with RSpec

20 views
Skip to first unread message

Jeff Fagot

unread,
Feb 20, 2018, 5:09:48 PM2/20/18
to rspec
Hello,

I am posting here because I am using RSpec, even if this question is probably broader than the framework I am using...

A little background:
Basically I am a manual tester of web applications who is trying to make his way toward automation using RSpec with WATIR gem.
I feel like BDD is the natural path coming from manual testing. I must confess that I had initially started using Cucumber but after being advised to avoid that "overhead" and "simply" use RSpec (which is compatible with Cucumber), so I did but not without questioning myself...
Also I am barely starting with Page-Object and still have nothing to manage my data... (I have only wrote a couple of simple scenarios so far)

Here is my problem:
I usually tend to create integration/End-to-End tests (Always dependent on data state).
So when I go to write my _specs, they always starts by a specific state, then I try to DRY them up as follow:
 1. Create sort of "Unit Test" Scenarios
 2. Make my Unitary Scenarios functions of variable, so I can re-use the same for all(as much as possible) cases

Now I am wondering what to do? or maybe how to structure myself?

QUESTIONS:
 1. Should I turn what I call Unitary Scenario/Test into actual Function/Module? To then be used into true integration test specifications?
 OR
 2. Should I have Unit Tests and Integration Tests _specs either into different files or "tagged"
 3. Maybe a mix of both?

 How to mediate to 'data state' related issues??
For example, if I am writing 2 tests : 1 for ADD, 1 For DELETE an element. Each test needs to be in the opposite state of the other. So my only chance to test them both is either run them dependently from one another or to create data specific for each test (which I cannot always afford, which is why I do more of what I call integration where I make weird scenarios accumulating this sort of dependency tests).

I would appreciate any insights. Also if someone could share some project examples that would enlighten me, it would be much appreciated.

Thanks for sharing your experience!
Jeff

Myron Marston

unread,
Feb 20, 2018, 7:29:34 PM2/20/18
to rs...@googlegroups.com
Hi Jeff,

So my only chance to test them both is either run them dependently from one another or to create data specific for each test (which I cannot always afford, which is why I do more of what I call integration where I make weird scenarios accumulating this sort of dependency tests).

Having each test be independent is really important.  The fact that it's too expensive to create data specific for each tests suggests that your testing strategy is poorly suited to provide the benefits you're looking.  End-to-end tests like the ones you're working on are generally the most expensive tests on every project and I favor having very few of them, pushing most tests down to the unit test level.  That generally requires that the tests are written in conjunction with the production code in order to influence its design, so that may not be feasible in your case.

I don't think we're going to be able to give you satisfactory answers (as we'd have to dig into your project in more detail to do that, and I don't have the time for that).  I think that some books that help you think about the costs and benefits of different approaches to testing could help you, though.  If you're looking for an RSpec-specific book, I'd recommend Effective Testing with RSpec 3, which was published about 6 months ago.

Good luck!
Myron



--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+unsubscribe@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/cc503083-5058-4287-916a-0d39659f05ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeff Fagot

unread,
Feb 21, 2018, 11:11:20 AM2/21/18
to rspec
Thank-you Myron for your prompt reply and for your book!

Yes I understand the cost and benefits of the different strategy, but you must understand that I primarily am doing this automation project for myself.
I cannot really apply true unit test strategy for many reasons. 

I will try later to post a simple glance of what I wrote to facilitate the exposure of my struggles and in hope that it benefits others too.

Thanks!!
JFF

To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages