Giter Site home page Giter Site logo

junit2spock's Introduction

junit2spock

Build Status GitHub release

Overview

This project aims to ease transition from Junit to Spock by converting Junit based test suites to Spock specifications. Please note that conversion is done on best effort basis and it may happen that it will produce invalid Spock spec or even invalid Groovy code. Even if tool converts test without syntax errors it is advisable to go through generated test classes and compare them with the orginal Junit tests.

Supported Features

  • JUnit 4
    • converting Junit @Test to specification method
    • converting methods marked with @Before, @After, @BeforeClass, @AfterClass annotations to fixture methods
    • replacing assertEquals, assertFalse, assertNotNull, assertNull, assertTrue with simple comparisons in then/expect block
  • Mockito
    • replacing Mockito mocks with Spock mocks
    • replacing given/willReturn, when/thenReturn for defining returned value with stubbed interaction (single value or sequence o values)
    • replacing given/willThrow, when/thenThrow for defining mocked method throwing an exception with stubbed interaction
    • replacing verify with Spock interaction verification
      • supported VerificationModes: never, atLeastOnce, times, atMost, atLeast
      • supported Matchers: any, anyByte, anyChar, anyCollection, anyCollectionOf, anyDouble, anyFloat, anyInt, anyIterable, anyIterableOf, anyList, anyListOf, anyLong, anyMap, anyMapOf, anyObject, anySet, anySetOf, anyShort, anyString, anyVararg, contains, endsWith, eq, isA, isNotNull, isNull, startsWith
      • partial support of matchers: argThat, booleanThat, byteThat, charThat, doubleThat, floatThat, intThat, longThat, shortThat
    • replacing verifyNoMoreInteractions with Spock equivalent
  • given/when/then blocks autodiscovery
  • Groovisms - Groovy's syntactic sugar
    • removing redundant semicolon at the end of the line
    • removing redundant public keyword
    • changing quotation in String literals to single quotation mark
    • removing .class in class literals

Run

Tool requires Java 8.

Download junit2spock-jar-with-dependencies.jar from latest release and run the following command to convert Junit test classes into Spock's specs:

java -jar junit2spock-jar-with-dependencies.jar path_to_junit_tests output_path

Build prerequisites

  • Java 8
  • Maven 3

Contributions and bug reports

Contributions as well as the bug reports are very welcome.

junit2spock's People

Contributors

opaluchlukasz avatar

Watchers

 avatar

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.