Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between cypress and a BDD framework like cucumber

can someone explain me the difference between cypress.io as testing framework and a BDD framework like cucumber e.g. As far as I understand cypress.io is a ui-testing framework for javascript. tests are written in javascript. you can use scenarios to describe a flow through the app as e2e-test. Is that similar to a behavior test or has this framework only focus on the ui?

Someone comes around the corner and says: Cucumber or JBehave is the same as cypress. I fear that's not true. but what are the arguments that can be answered. I don't develop web-apps and it's hard for me to compare both solutions.

I try to clarify my question: Imagine there's an application with backend services and a frontend (web-app) that uses these services. The backend represents complex workflows and the whole app shall be tested by a BDD Framework (e.g. cucumber). The major benefit is a kind of up-to-date documentation by feature- and scenario-descriptions. It's the core of a framework like cucumber. A further benefit it's of course the (maybe e2e) test itself. To have value it needs ui-testing to test the whole workflow. e.g. you could use selenium together with cucumber to handle this. I think cypress is a kind of testing framework like selenium, right? Only much better in many ways. But someone could say: "oh ... cypress is the same as cucumber, because you can also define scenarios, etc ... But I believe, when we think about BDD then cypress has to be used in combination with cucumber and not as a new stand-alone BDD-Tool. From my point of view cypress is a great ui-testing framework, but ... not more?! I anncounced my question here to find answers for clarification.

like image 792
JMarky Avatar asked Nov 14 '17 09:11

JMarky


People also ask

Is Cypress A BDD tool?

Cypress is a popular frontend test automation framework, designed to help developers in creating and maintaining end to end tests. Together with Cucumber, a Behavior Driven Development (BDD) tool, tests will be both clean to write and maintain.

What is the difference between BDD and Cucumber?

Cucumber is a free or open-source BDD (Behavior Driven Development) tool. Selenium is also a free or open-source testing tool. Cucumber is a BDD supported tool. Selenium is a both Functional and Performance (Selenium Grid) testing tool.

Does Cypress use Cucumber?

Cypress provides integration with Cucumber for writing the test scenarios in BDD format. Cypress uses all the capabilities of Cucumber by using the Cucumber-preprocessor node module. Similar to other Cucumber implementations, with Cypress also, it uses the RegEx mapping.

Is Cucumber a BDD framework?

The answer is, Behavior Driven Development (BDD) Framework. Cucumber is one such open source tool, which supports behavior driven development. To be more precise, Cucumber can be defined as a testing framework, driven by plain English text.


2 Answers

You touch on a lot of things in your post. I'd like to try to help with some general classifications that might help you understand what you will get with the different technologies.

BDD(Behavior Driven Development):
This is less of a technology and more of a "way" of testing. Similar to TDD by name and acronym but very different in approach. TDD is the idea that you write a set of test before you start to code, and the code you write should be done when it passes those tests. Most commonly done by developers as part of the development process. A very important distinction is that TDD DOES test the implementation. BDD does not. You want to negate the implementation and only test the BEHAVIOR, or the user facing functionality of the application. That doesn't mean it is always an end user. You could test a backend with BDD style tests. The important thing is that with BDD you care about the output and should NOT be testing the implementation.

Cypress vs Cucumber:
These are two different things. Cypress CAN use Cucumber(here is a link of a package that helps you do just that) By default it uses Mocha, yet another BDD syntax you can use to organize your tests... Important take away: Cucumber is a syntax that has your code referenced by GIVEN, WHEN, or THENS that represent Preconditions?setup, the action under test, and the expected result. The cool thing about Cucumber is your code is called up by these GIVEN/WHEN/THEN "steps". Why that is important is someone reading the test, they can be sure that if the GWT step is the same step in a different tests, both would use the same under lying code... Pretty cool, huh? Cucumber is a way of writing highly readable test and allowing others to read or write test and now that the underlying code will be the same. You can write new tests by just reorganizing the GWTs! You can also use RegEx expressions to allow for test case parameterization. You can even connect those parameters to a data table! Here is an EXAMPLE

How is Cypress.IO different than Selenium?
This could be an entire article on it's own. I will present the most important difference for me. The architecture... Here is a link to the diagram from this post. What is significant about that? The app under test runs INSIDE of a container controlled by cypress. That allows a tester to stub request(inward data) and spy or mock data(outward data). This goes beyond the obvious network traffic. You can even stub functions of the browser. Cypress doesn't support multi-tab testing. No biggie, you stub the new window(or tab) action, and when the app under test fires that, it simply opens the URL in the same window. This is nothing short of amazing as you can do this with almost any function or traffic. It isn't easy though if you don't have decent programming knowledge. Devs can help.

What cypress is not
UPDATE: Cross-browser testing now has limited support with Cypress4.0. covering Firefox and MS Edge(>=79).

Fun fact: MS Edge version numbers jumped from 44.xx to 79.xx when they changed to the chromium engine so that their version numbers would sync with chrome...

Cross-browser testing is not supported at the moment. You can only test in chrome.

You mentioned backend, ui, and e2e testing above
Cypress is typically used to test frontend or UI. It can be used for integration testing, and possibly unit testing(might be better to use something like jest instead). It also has the ability to fire REST request using the cy.request command. You could write some API testing with and some javascript, but a tool like postman would be better for a comprehensive testing suite for an API.

Selenium could be use similarly for UI, API and e2e testing. You can't use it for lower level integration testing or unit testing. They have libraries that can help you with REST(API) testing, but you'd want to use an API testing tool for a large suite. Both cypress and Selenium support API testing to allow for sending calls to speed up test(logging in to the backend and obtaining a token that gets added to local storage instead of hitting the UI and having it handle the token setup for you).

Sounds like you are still pretty new to automated testing. It is tough at first but a great field. I would research some of the stuff I mentioned above in greater detail. Feel free to ask for more clarification. Happy Testing!!!

like image 107
NANfan Avatar answered Sep 16 '22 16:09

NANfan


Updated answer

If what you're asking is whether Cypress can be used for more than unit testing the UI, the answer is yes, from the first page of the docs:

Cypress enables you to write all types of tests: - End to end tests - Integration tests - Unit tests

Try reading the rest of the documentation to get an idea of the tool's capabilities; the Stack Overflow community can answer questions for you, but they can not (and certainly will not) do your homework for you.

Also: Try being more concise in your questions, both in the title and in the description. Brevity is often a sign of having a clearly defined problem, while verbosity is not, and your long description doesn't serve your question well.

The core of this question is not the difference between Cypress and Cucumber, it is: "Can Cypress be used for more than just unit testing the GUI? I am also interested in testing stuff like the database [and so on ...]"

A sad fact of Stack Overflow is that you don't any responses if you don't make your question easy to answer. Good luck with taking this constructive criticism to heart and making your upcoming questions readable and concise.

Original answer

I would encourage you to ask questions that can have a clearly defined, factual answer, not one in which the answer depends on subjective evaluations, such as the one I am about to give. But here goes:

To my untrained eye (having no experience with Cucumber and some weeks of experience with Cypress), the main difference between Cucumber and Cypress is that Cucumber seems to be aimed at testing in general, not just for the web, and has to be run using some test framework (such as Selenium): https://cucumber.io/docs Cypress specializes in web-testing and provides everything you need to run it as one installable package, including its own test framework: https://www.cypress.io/how-it-works/

like image 25
vages Avatar answered Sep 20 '22 16:09

vages