I always wonder this as I write integration tests: at what point is the test "too" long.

For example I have some tests that go through a website to create various things (Widgets) we'll call them.

I'm using FactoryGirl to basically set up the "minimal" amount of information needed in the database. (Users/Companies) mainly that this widget gets created under.

However, I also want to test deleting of the widget. So....I can either set up every single part of the "Widget" creation from within various factories, which is both time-consuming, ugly and technically incorrect. (Technically incorrect because to delete something, a user would have to create it first as opposed to it just "being there", and ugly...I guess because you are adding a ton of factories just to support a simple deletion test)

or I can go through the creation of the widget process THEN deleting the widget in one test.

Is this bad practice? It mimics what the user would do more-so than setting up the widget data and then having a small test that clicks a delete button. Or am I looking at this the wrong way?


  • Can you please elaborate why your first approach is "ugly and technically incorrect?"
    – Yu Zhang
    Feb 2, 2017 at 20:05
  • I added an edit to explain, maybe the "ugly" part is just my opinion though.
    – Mercfh
    Feb 2, 2017 at 20:16
  • I'd argue the mock scenario is an integration test, while the creation/deletion is the end-to-end test. They both have some value. Does the deletion have a unit test?
    – ernie
    Feb 3, 2017 at 0:51

1 Answer 1


My personal interpretation is:

  • you have two different ways to create a widget, one is to create via factories in the back end. enter image description here
  • while second one is to create on the front end as a user would. enter image description here

Both of approaches have their pros and cons:

  • If you create a widget the ugly way, its con is it does not simulate a user will do in real life and hence you are testing the front end effectively, and it is hard for you to delete it. Its pro is you can create widgets in batch, you may need a test scenario that requires a large number of widgets to be created.
  • If you create a widget on the front end interactively, its pro: it is a more realistic testing scenario and you can delete it easily. Its con: only one widget can be created each time, it is relatively slow to create widgets in large numbers.

Depends on your actual testing requirements, you may need to accommodate both approaches.

  • 1
    Step 2 seems like it's best for "reasonable/not super long tests" but I try to create minimal factories to keep things at a blank slate. But I suppose if Im needed to go through multiple avenues to test one thing factories may be better.
    – Mercfh
    Feb 2, 2017 at 20:46
  • @Mercfh, should you need to discuss this further, please come back anytime.
    – Yu Zhang
    Feb 2, 2017 at 21:02
  • Nice handwriting.
    – user246
    Feb 2, 2017 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.