Lamdba Behave alternatives and similar libraries
Based on the "Testing" category.
Alternatively, view Lamdba Behave alternatives based on common mentions on social networks and blogs.
-
Mockito
Most popular Mocking framework for unit tests written in Java -
Apache JMeter
Apache JMeter open-source load testing tool for analyzing and measuring the performance of a variety of services -
TestContainers
Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container. -
MockServer
MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding). -
PowerMock
PowerMock is a Java framework that allows you to unit test code normally regarded as untestable. -
Awaitility
Awaitility is a small Java DSL for synchronizing asynchronous operations -
AssertJ
AssertJ is a library providing easy to use rich typed assertions -
ArchUnit
A Java architecture test library, to specify and assert architecture rules in plain Java -
Pact JVM
JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project. -
Selenium
Portable software testing framework for web applications. -
JSONAssert
Write JSON unit tests in less code. Great for testing REST interfaces. -
JMockit
Advanced Java library for integration testing, mocking, faking, and code coverage -
Citrus
Framework for automated integration tests with focus on messaging integration -
System Rules
A collection of JUnit rules for testing code which uses java.lang.System. -
junit-dataprovider
A TestNG like dataprovider runner for JUnit with many additional features -
ConcurrentUnit
Toolkit for testing multi-threaded and asynchronous applications -
Jukito
The combined power of JUnit, Guice and Mockito. Plus it sounds like a cool martial art. -
Mutability Detector
Lightweight analysis tool for detecting mutability in Java classes -
Arquillian
Integration and functional testing platform for Java EE containers. -
Randomized Testing
Randomized Testing (Core JUnit Runner, ANT, Maven) -
Spectrum
A BDD-style test runner for Java 8. Inspired by Jasmine, RSpec, and Cucumber. -
Scott Test Reporter
Never debug a test again: Detailed failure reports and hassle free assertions for Java tests - Power Asserts for Java -
pojo-tester
Java testing framework for testing pojo methods. It tests equals, hashCode, toString, getters, setters, constructors and whatever you report in issues ;) -
YAKS
YAKS is a platform to enable Cloud Native BDD testing on Kubernetes -
raml-tester
Test if a request/response matches a given raml definition
Access the most powerful time series database as a service
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Lamdba Behave or a related project?
README
Introduction
If you're a Java developer and you've seen the fluent, modern specification frameworks available in other programming languages such as spock or jasmine then Lambda Behave is for you. Its goal is to make testing a more pleasant experience than it currently is with junit.
The changelog explains what features have been added in each release.
Fluent Specifications
The Lambda Behave Specification design has several goals in mind:
- To read like plain English.
- To encourage describing tests using long and descriptive sentences, rather than a few words.
- An API that is fluent and discoverable nearly entirely through IDE auto-completion.
public class StackSpec {{
Stack<Integer> stack = new Stack<>();
describe("a stack", it -> {
it.isSetupWith(stack::clear);
it.isConcludedWith(stack::clear);
it.should("be empty when created", expect -> {
expect.that(stack).isEmpty();
});
There are many, many, expectations builtin to the framework - not just isEmpty()
.
Every specification suite starts its declaration using the Suite.describe
method. From that point onwards your IDE should be able to auto-complete the domain specific language for declaring specifications, but just in case you want more information, here's the details.
- If you want to specify a property about your system use
it.should
. - If you want describe an expectation of that property, use
expect.that
. This will get you to a fluent API restricted to the type of value that you're making the expectation about. The expectation system is based upon hamcrest. Lambda Behave doesn't compromise the ability to compose matchers in favour of fluency - if you want to compose in more complex flavours simply useexpect.that(value).is()
and then you can use regular Hamcrest matchers. In my experience this is a rare, albeit useful, breakout option. - If you want to setup or teardown data before or after each specification use
it.isSetupWith
andit.isConcludedWith
. - If you want to setup or teardown data before or after each suite use
it.initializesWith
andit.completesWith
. - Don't worry - I know some Java 8 lambdafied APIs don't deal with exceptions very well but you can throw exceptions in all our callbacks and the appropriate error will be reported, not just break the library.
Data Driven Specifications
The ability to parametrise specifications by different data inputs.
Data driven tests in TestNG or the @Parameterized
junit annotation perform a similar task.
@Parameterized
only parameterises at the level of a class, whereas Lambda Behave parameterises at the level of a specification.
describe("a pair of numbers", it -> {
it.uses(4, 2)
.and(6, 3)
.toShow("%d / %d is two", (expect, x, y) -> {
expect.that(x / y).is(2);
});
});
The API in Lambda Behave is both fluent and also type safe and doesn't rely on reflection magic.
The uses
method is overloaded to allow a different number of columns of data to be used. It also supports taking
streams or lists of data as its inputs, rather than explicitly chaining individual values.
Not only is the specification parameterised by the data, but the description is also parameterised, its name being interpreted as a format String
.
The aforementioned test would output the following:
a pair of numbers
4 / 2 is two
6 / 3 is two
Generated Specifications
Lambda Behave can automatically generate testcases for your to test your code with, similar to quick check or scala check.
The Fluent API for this is similar to data driven specifications allows for control over the way that the values are generated
and how many need to be generated. Here is an example of how to show that reversing a String
twice returns the same String
using randomly generated test case values.
it.requires(10)
.example(asciiStrings())
.toShow("reversing a String twice returns the original String", (expect, str) -> {
String same = new StringBuilder(str).reverse().reverse().toString();
expect.that(same).isEqualTo(str);
});
All generated specifications follow this common pattern where;
- The
require
clause expresses how many values to generate, - The
example
clause states what type of objects to generate and how to generate them, This is overloaded to allow multiple columns of testcase values to be generated. - The
toShow
clause behaves like atoShow
clause for a data drive spec. It is type safe against the the different columns. So in the above example the paramterstr
will have had its type correctly inferred asString
.
Downloading Lambda Behave
If you're using a maven project then you can download Lambda Behave using the following pom entry.
<dependency>
<groupId>com.insightfullogic</groupId>
<artifactId>lambda-behave</artifactId>
<version>0.4</version>
<scope>test</scope>
</dependency>
If you're using a gradle project then you can use:
testCompile group: 'com.insightfullogic', name: 'lambda-behave', version: '0.3'
There's also an example project and there's published Javadoc.
Junit Integration
Lambda Behave also offers a junit runner. This lets you easily integrate into existing your existing test suite, or the tests via an Eclipse, Intellij, Netbeans, Maven, Gradle or Ant. You just add an annotation to enable this, and it can be run through your normal tooling.
@RunWith(JunitSuiteRunner.class)
public class StackSpec {{
Lambdas - what the hell are they?
Conveniently I've written a book on Lambda expressions in Java 8 and the cleaner code they enable!
Licensing
This library is licensed under the liberal MIT license - see LICENSE for the full details. This means that it's free for any use.
More Details and How to contribute
The wiki has more information.
*Note that all licence references and agreements mentioned in the Lamdba Behave README section above
are relevant to that project's source code only.