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?
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.
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.
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); }); }); }}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With