Giter VIP home page Giter VIP logo

java-testing-with-spock's Introduction

Java Testing with Spock

Current build status: Build Status

Java Testing with book cover

Description

This GIT repository contains all source code for the book Java Testing With Spock published by Manning. Each chapter is offered as an independent Maven project.

Free chapter 1 - (intro to testing)

You can get an overview of Spock and read a brief discussion on its features in the first chapter of the book. This chapter is freely available in PDF format.

Free chapter 3 - (comparison with JUnit)

The book contains a comparison of JUnit and Spock using semi-real world code examples. If you are a die-hard JUnit believer, you will find this part of the book very interesting. This chapter is also freely available in PDF format.

Requirements

To use the code samples you need the following:

  • Java Development Kit version 7+
  • Maven installed (mvn should be available in the command line)
  • Internet access (for fetching library dependencies)

Usage

You can checkout/run any chapter on its own. You can either work directly on Github or download the code as a ZIP file For each chapter entering the command mvn test will compile and run all JUnit/Spock tests.

IDE support

Each chapter is self-contained. There is no super POM file. This repository is NOT a multimodule project. If you use Eclipse just import any chapter as a Maven project. If you use IntelliJ make sure that you import each chapter on its own project (and not as modules in a single project). To gain syntax highlighting you also need to install Groovy support in your IDE. This is optional because the build is fully automated via Maven.

Gradle Support

There are also build.gradle files along side each maven pom.xml file in each chapter if you would like to see what an analogous gradle build file looks like. You also do not have to download and install Gradle either as the gradle wrapper files are also included in this repository. Simply type ./gradlew clean test at the project root and Gradle will build the project and run the tests.

You can also import the build.gradle files into Eclipse if you have the Gradle Buildship plugin installed. If you are using Intellij IDEA, you can also import each chapter on its own similar to how Maven projects are imported. The idea and eclipse plugins are also configured in each build.gradle file if you want to generate the metadata files for Eclipse and IDEA projects.

Note that Gradle support was contributed by [Mike Smithson] (https://github.com/mikesmithson) and is considered a bonus feature. I will provide no support for Gradle and any related issues, i.e., you are on your own.

Code listings

Chapter 1

Chapter 2

Chapter 3

Chapter 4

Chapter 5

Chapter 6

Chapter 7

Chapter 8

Issues with the code.

If you find a problem with the code feel free to open an issue. If you feel like contributing you can even create a pull request!

Issues with the book

If you have comments and suggestions for the book please use the Manning forum. I monitor it regularly and it is helpful if other readers can see and respond to your comments.

Enjoy!

java-testing-with-spock's People

Contributors

francescobianchi avatar jonatasemidio avatar kkapelon avatar lreimer avatar mikesmithson avatar willis7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

java-testing-with-spock's Issues

Tests Fail in GroovyFilesSpec of Chapter 2

If you run the tests from within the IntelliJ IDE the tests fail, but if you run them from the command line using: mvn test the tests pass.

Stacktrace:
java.io.FileNotFoundException: src/test/resources/quotes.txt (No such file or directory)
at java.io.FileInputStream.(FileInputStream.java:146)
at groovy.util.CharsetToolkit.(CharsetToolkit.java:69)
at com.manning.spock.chapter2.GroovyFilesSpec.demo for reading a text file line by line(GroovyFilesSpec.groovy:20)

Help

I have two issues. I am trying to buy your book on Manning's site and it won't add to my cart.

I am hoping it will help with a problem I am having. I have a test like this:

import spock.lang.Specification

class EmployeeTest extends Specification {
def "a valid employee should be valid"() {
given:
def Employee employee = new Employee()
def User mockUser = Mock(User)

    when:
    BusinessServiceResult bsResult = employee.prepareForPersistance("aTransactionId", "aTransactionName", mockUser);

    then:
    bsResult != null
    bsResult.isSuccessful()
}

}

I get

groovy.lang.MissingMethodException: No signature of method: com.pbi.datanet.model.businessobject.bo.Employee.prepareForPersistance() is applicable for argument types: (java.lang.String, java.lang.String, com.pbi.datanet.model.businessobject.bo.User$$EnhancerByCGLIB$$20359d67) values: [aTransactionId, aTransactionName, Mock for type 'User' named 'mockUser']
Possible solutions: prepareForPersistence(java.lang.String, java.lang.String, com.pbi.datanet.model.businessobject.bo.User)

but I have seen in your code here that you pass mocks as real objects. Sorry to leave this here it's the only way I could find to contact you.

Add Gradle Builds

Hi,
I have taken an interest in Spock and have looked to the Manning book for learning about it. I have forked your repository and have started working on providing Gradle build scripts. Once completed, I would like to make a pull request to have the Gradle build scripts merged into your repo. Is this something you would find of value?

Thanks,

Mike

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.