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.
@Test
to specification method@Before
, @After
, @BeforeClass
, @AfterClass
annotations to fixture methodsassertEquals
, assertFalse
, assertNotNull
, assertNull
, assertTrue
with simple comparisons in then/expect blockgiven/willReturn
, when/thenReturn
for defining returned value with stubbed interaction (single value or sequence o values)given/willThrow
, when/thenThrow
for defining mocked method throwing an exception with stubbed interactionnever
, atLeastOnce
, times
, atMost
, atLeast
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
argThat
, booleanThat
, byteThat
, charThat
, doubleThat
, floatThat
, intThat
, longThat
, shortThat
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
Contributions as well as the bug reports are very welcome.