Unit tests should only test one thing . The test, which begins with "going to the product page, searching for the product and adding it to the basket," there are three different things, doesnβt look like a unit test at all, but an integration test. I suspect you have two different tests to create here.
Your integration test, in a cucumber or something similar, should consist of several stages:
When I navigate to the products page And I search for a product And I add it to the cart
You can identify each step once and use it several times, making it pleasant and dry.
Your unit test, on the other hand, should drown out all the necessary settings and just check one that interests you:
before stub(cart) stub(product) click on "X" for item in cart it should... expect(cart not to contain item) expect(product count to be updated)
If this turns out to be really complicated and involves a lot of stubbing, this is an indication that your code is not modular; the solution relates to TDD and records tests first, rather than adding them later.
source share