All Projects → opaluchlukasz → junit2spock

opaluchlukasz / junit2spock

Licence: MIT license
JUnit test to Spock test converter

Programming Languages

java
68154 projects - #9 most used programming language
groovy
2714 projects

Projects that are alternatives of or similar to junit2spock

gathering
A self hosted website for announcing group events
Stars: ✭ 39 (+160%)
Mutual labels:  spock
funblog
A simple blog software written in Haskell
Stars: ✭ 84 (+460%)
Mutual labels:  spock
geb-mobile
A geb navigator factory for mobile support for Appium, Selendroid and IosDriver
Stars: ✭ 18 (+20%)
Mutual labels:  spock
onboarding-service
Backend Onboarding Service for Tuleva
Stars: ✭ 21 (+40%)
Mutual labels:  spock
job-dsl-sample
Jenkins Job DSL Sample Project
Stars: ✭ 32 (+113.33%)
Mutual labels:  spock
spring-spock-integration-testing
How to inject Spock mocks into Spring integration tests
Stars: ✭ 17 (+13.33%)
Mutual labels:  spock
spock
Automatically perform git commits, pushes, and other cli actions when Statamic content changes
Stars: ✭ 96 (+540%)
Mutual labels:  spock
springmock
alternative spring mocking infrastructure
Stars: ✭ 22 (+46.67%)
Mutual labels:  spock
spring-boot-web-application-sample
Real World Spring Boot Web Application Example with tons of ready to use features
Stars: ✭ 143 (+853.33%)
Mutual labels:  spock

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].