Testing / Cucumber Interview Questions
What is the difference between Cucumber and TestNG/JUnit as testing tools?
TestNG and JUnit are general-purpose Java test frameworks: tests are written directly as annotated Java methods, with assertions and test logic living entirely in code. Cucumber isn't a competing alternative to them so much as a layer that sits on top of one of them, using JUnit (or TestNG) as the actual mechanism that discovers and runs the underlying test cases Cucumber produces from Gherkin.
| Cucumber | TestNG / JUnit |
| Tests specified in plain-language Gherkin feature files. | Tests written directly as Java methods with annotations. |
| Business-readable, no Java knowledge needed to read a scenario. | Requires reading Java code to understand what's being tested. |
| Runs on top of JUnit or TestNG as its execution engine. | Is itself the execution engine, with no additional specification layer. |
In practice a Cucumber-JVM project always has JUnit (or TestNG) underneath it somewhere, since that's what actually executes on the JVM; the meaningful comparison isn't "Cucumber versus JUnit" as competitors, but "writing tests as plain Gherkin plus step definitions" versus "writing tests directly as annotated Java test methods," two different authoring styles that can both ultimately run through the same underlying JVM test infrastructure.
More Related questions...