background preloader

Testing

Facebook Twitter

Introducing BDD. History: This article first appeared in Better Software magazine in March 2006.

Introducing BDD

It has been translated into Japanese by Yukei Wachi, Korean by HongJoo Lee, Italian by Arialdo Martini and French by Philippe Poumaroux and most recently into Spanish by Oscar Zárate, Turkish by Selim Öber and Russian. I had a problem. While using and teaching agile practices like test-driven development (TDD) on projects in different environments, I kept coming across the same confusion and misunderstandings. Gojko Adzic - BDD: Busting the myths. What’s in a Story? [This article has been translated into Korean by HongJoo Lee, French by Philippe Poumaroux, Spanish by Adrian Moya, Russian by Denis Oleynik, and German by Julia Kadauke.]

What’s in a Story?

Behaviour-driven development is an “outside-in” methodology. It starts at the outside by identifying business outcomes, and then drills down into the feature set that will achieve those outcomes. Each feature is captured as a “story”, which defines the scope of the feature along with its acceptance criteria. This article introduces the BDD approach to defining and identifying stories and their acceptance criteria. Introduction Software delivery is about writing software to achieve business outcomes. Usually, the business outcomes are too coarse-grained to be used to directly write software (where do you start coding when the outcome is “save 5% of my operating costs”?) This, then, is the role of a Story. The structure of a story BDD provides a structure for a story. Telling the story The characteristics of a good story. Necesito recomendacion para libros de BDD y user story. JUnit Testing Spring Service and DAO (with In-Memory Database)

This post describes how to implement JUnit tests for a Spring Web Application’s Services and DAO.

JUnit Testing Spring Service and DAO (with In-Memory Database)

It is built on top of the Spring MVC-Service-DAO-Persistence Architecture Example. This example is available from Github in the Spring-Web-JPA-Testing directory. Reminder Test Fixture – The fixed state used as a baseline for running tests.Unit test – These tests verify that pieces of code (components) perform some functionalities as expected. In a Java environment, these are typically implemented at the class level.Integration test – Integration testing is any type of test checking that a set of interacting components perform expected functionalities together correctly.

Configuration. John Ewart » DAO Testing with Hibernate. I’m currently building some web services using Dropwizard (Jetty, Jersey, Jackson, Hibernate all bundled up), and needed to test the DAO.

John Ewart » DAO Testing with Hibernate

Dropwizard has some convenient interfaces to load configuriation files and bring up hibernate sessions, etc. when the service boots up; however, this does not translate well to JUnit tests (there’s a lot of plumbing involved in making a Service that doesn’t translate to tests.) Fortunately, though, since it’s all just sugar coating you can just as easily setup your own sessions and transactions. I found that creating a parent class for my DAO tests that does all the setup is a convenient way of handling all the plumbing you need.

Learn Spring MVC 3, Hibernate, Maven, and TDD. Mockito - @Mock, @Spy, @Captor and @InjectMocks. I usually post about Dev stuff on Twitter - you can follow me there: 1.

Mockito - @Mock, @Spy, @Captor and @InjectMocks

Overview In this tutorial, we’ll cover all the annotations in the Mockito library – @Mock, @Spy, @Captor and @InjectMocks . 2. Enable Mockito Annotations First – let’s see how to enable the use of annotations with Mockito tests. In order for these annotations to be enabled, we’ll need to annotate the JUnit test with a runner – MockitoJUnitRunner as in the following example: Alternatively we can enable these annotations programmatically as well, by invoking MockitoAnnotations.initMocks() as in the following example: 3. The most used widely used annotation in Mockito is @Mock. In the following example – we’ll create a mocked ArrayList with the manual way without using @Mock annotation: And now we’ll do the same but we’ll inject the mock using the @Mock annotation: Mockito When/Then Cookbook. Testing Spring components with Mockito. Be able to unit test your spring components without the need of loading the full spring-context with its ad-hoc test configurations it is ,in my opinion, a great advantage because it's clean, easy to maintain, faster to write, smooth to alter.

Testing Spring components with Mockito

A way to achieve this goal is to use Mockito and tell him to replace the @Autowired components in the class you want to test, with Mocks ( or Spies ). Here an example. We have a service called SalaryService that guess what, is calculating a hypothetical net salary based on the employee id passed. Easy concept. The service required two collaborators, one, the EmployeeDAO, to retrieve the gross salary and a second one, the TaxCalculator, to apply some taxes based on the gross salary.

Remove duplications and fix bad names: Testing Spring components with Mockito. How cool is integration testing with Spring+Hibernate. I am guilty of not writing integration testing (At least for database related transactions) up until now.

How cool is integration testing with Spring+Hibernate

So in order to eradicate the guilt i read up on how one can achieve this with minimal effort during the weekend. Came up with a small example depicting how to achieve this with ease using Spring and Hibernate. With integration testing, you can test your DAO(Data access object) layer without ever having to deploy the application. For me this is a huge plus since now i can even test my criteria's, named queries and the sort without having to run the application.

There is a property in hibernate that allows you to specify an sql script to run when the Session factory is initialized. <prop key="hibernate.hbm2ddl.import_files">import.sql</prop> <prop key="hibernate.hbm2ddl.import_files">import.sql</prop> According to the hibernate documentation, you can have many comma separated sql scripts.One gotcha here is that you cannot create tables using the script. Learn Spring MVC 3, Hibernate, Maven, and TDD.