background preloader

Test

Facebook Twitter

Fluent-builders-generator-eclipse-plugin - Fluent builders generator for Eclipse. A plugin that is going to change your way of creating Java objects, by leveraging the idea of fluent interfaces. By using it, You get: ease of creating objects in one clean and readable method-chain clever collections support creation of complex object trees empowered by IDE's code completion What is the idea of Fluent builders ? Fluent Builder is a variant of the Builder pattern that uses Fluent interface. Fluent builders are especially handy when instantiating data objects within unit tests. To see the benefit, compare following two examples: 1.

@Test public void shouldFindByActorWithFluentBuilder() { // given List<Movie> movies = Arrays.asList( MovieBuilder.movie().withTitle("Blade Runner") // <- here's the builder used .withAddedActor("Harrison Ford") .withAddedActor("Rutger Hauer") .build(), MovieBuilder.movie().withTitle("Star Wars") // <- ... and also here .withAddedActor("Carrie Fisher") .withAddedActor("Harrison Ford") .build()); 2. Movie movieStarWars = new Movie(); Plugin usage. Mistaeks I Hav Made: Test Data Builders: an alternative to the Object Mother pattern. If you are strict about your use of constructors and immutable value objects, constructing objects in a valid state can be a bit of a chore. Usually in application code, such objects are constructed in few places and all the information required by the constructor is at hand, having been provided by user input, obtained from a database query or received in a message for example.

In tests, on the other hand, you have to provide all those constructor arguments every time you want to create an object, whether to test its behaviour or to create a value to use as input to the code being tested. Invoice invoice = new Invoice( new Recipient("Sherlock Holmes", new Address("222b Baker Street", "London", new PostCode("NW1", "3RX"))), new InvoiceLines( new InvoiceLine("Deerstalker Hat", new PoundsShillingsPence(0, 3, 10)), new InvoiceLine("Tweed Cape", new PoundsShillingsPence(0, 4, 12)))); The Object Mother pattern is one attempt to avoid this problem.

A solution is to use the Builder Pattern. To: Selenium - Web Browser Automation. Cucumber - Making BDD fun. Org.mockito Class Hierarchy (Mockito API) Testing legacy code with Golden Master. As a warm up for SCNA, the Chicago Software Craftsmanship Community ran a hands-on coding session where developers, working in pairs, should test and refactor some legacy code. For that they used the Gilded Rose kata. You can find links to versions in java, C# and ruby here and for clojure here. We ran the same session for the London Software Craftsmanship Community (LSCC) early this year and back then I decided to write my tests BDD-style (I used JBehave for that).

You can check my solution here. This time, instead of writing unit tests or BDD / Spec By Example to test every branch of that horrible code, I decided to solve it using a test style called Golden Master. The Golden Master approach Before making any change to the production code, do the following: Create X number of random inputs, always using the same random seed, so you can generate always the same set over and over again. Approval Tests The first time the test method is executed, the line: Thanks. Approval Tests Library - Capturing Human Intelligence [available for Java, C#, VB.Net, PHP or Ruby] | ApprovalTests.