Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Cucumber and Gherkin alternatives to Mocha and Chai? Can Mocha and Chai be used with Java code? [closed]

If someone can point out any other source on StackOverflow etc. where more info about this exists, even that will be helpful.

like image 207
user3251882 Avatar asked Mar 14 '16 17:03

user3251882


People also ask

Which is better mocha or cucumber?

js or Mocha? There is no clear answer to this question, but here is my advice: if you have engaged stakeholders who are willing to read or even write the Gherkin code, go for Cucumber. js. If you are not in this (fortunate) situation, then using Cucumber.

What is mocha chai used for?

Introduction to Unit Testing with Mocha and Chai Mocha is a widely used JavaScript test framework running on NodeJS and browsers. It supports asynchronous testing running the tests serially, allowing for more flexible and accurate reporting.

Why are gherkins used in cucumbers?

Gherkin is Cucumber's language parser, which allows software behaviours to be specified in a logical language that people can understand. This means that Cucumber feature documentation is written in business-facing text that is non-technical and human readable for stakeholders like business analysts and managers.

What is mocha and chai?

Mocha and Chai are two JavaScript frameworks commonly used together for unit testing. Mocha is a testing framework that provides functions that are executed according in a specific order, and that logs their results to the terminal window.


1 Answers

Cucumber is an acceptance testing framework which enables tests that are readable by non-programmers. Gherkin is just the syntax in which those tests are written. The implementation of those non-programmer friendly tests can be written in multiple languages including Java, Javascript and Ruby. For testing web applications, there are tight integrations of browser drivers (Selenium, PhantomJS, etc.) with Cucumber.

Mocha is a test framework in which tests are written in Javascript. Mocha tests are not especially friendly to non-programmers. Chai is just an assertion library used with Mocha. Mocha itself doesn't provide integration with browser drivers, but there are examples on the web of how to use Javascript browser drivers from within Mocha and at least one tight integration, CodeceptJS.

So, whether Cucumber and Mocha are alternatives depends on what language you want to write your tests in and whether you care about their readability by non-programmers. If you want to write your tests in a language other than Javascript, use a Cucumber implementation in that language. If you want tests readable by non-programmers, use Cucumber. If you want to write tests in Javascript and don't care about readability by non-programmers, both Cucumber.js and Mocha (plus a browser driver) are options. There are other Javascript-friendly options than Mocha, such as Protractor for Angular applications.

Regarding Java, any acceptance testing framework that drives a browser can test a web application written in Java. If you want to write the acceptance tests themselves in Java, you probably want Cucumber-JVM. JBehave is another, older, less widely used alternative.

like image 124
Dave Schweisguth Avatar answered Oct 12 '22 17:10

Dave Schweisguth