Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A BDD (RSpec-like) testing library for Java [closed]

Now that we have lambda expression it should be possible to have a Java unit testing library that offers a syntax similar to that of (say) RSpec. I imagine something like:

  describe("some behavior", () -> {
    beforeEach(() -> {
      // do some initialization...
    });
    describe("sub behavior 1", () -> {
      // some assertions ...
    });
    describe("sub behavior 2", () -> {
      // some assertions ....
    });
  });

Is there any library like that out there?

like image 947
Itay Maman Avatar asked Jun 05 '15 21:06

Itay Maman


People also ask

What is BDD in Java?

Behavior Driven Development (BDD) is a software development process that originally emerged from Test Driven Development (TDD). BDD uses examples to illustrate the behavior of the system that are written in a readable and understandable language for everyone involved in the development.

What is BDD framework in testing?

Behavior Driven Development (BDD) Framework enables software testers to complete test scripting in plain English. BDD mainly focuses on the behavior of the product and user acceptance criteria. Cucumber is one of the best tools used to develop in the BDD Framework.


2 Answers

Afaik, Oleaster is a lib that does that.

Oleaster allows you to write JUnit tests like you would write Jasmine tests.

An Oleaster JUnit test looks like this:

@RunWith(OleasterRunner.class)
public class OleasterIntroductionTest {{
    describe("A suite", () -> {
        it("contains a spec with an expectation", () -> {
            expect(40 + 2).toEqual(42);
        });
    });
}}
like image 143
acdcjunior Avatar answered Oct 18 '22 00:10

acdcjunior


Please consider spock, it was inspired from rspec and others.

It Just reached 1.0.

From the page...

In Behavior Driven Development, customer-facing features (called stories) are described in a given-when-then format. Spock directly supports this style of specification with the given: label:

> given: "an empty bank account" // ...
> 
> when: "the account is credited $10" // ...
> 
> then: "the account's balance is $10" // ... As noted
like image 29
Jayan Avatar answered Oct 18 '22 01:10

Jayan