Akashic Records

Java Testing with SPOCK 본문

오래된글/Java

Java Testing with SPOCK

Andrew's Akashic Records 2018. 4. 9. 11:12
728x90


SPOCK is a unit testing framework that in great exten utilizes Goovy’s syntax making your tests comprehensible and easy on the eyes. Spock makes writing tests fun.


Why SPOCK?

  • Spock is an alternative test framework written in the Groovy programming language.

  • A test framework automates the boring and repetitive process of manual testing, which is essential for any large application code base.

  • Although Spock is written in Groovy, it can test both Java and Groovy code.

  • Spock has built-in support for mocking and stubbing without an external library.

  • Spock follows the given-when-then code flow commonly associated with the BDD paradigm.

  • Both Groovy and Java build and run on the JVM. A large enterprise build can run both JUnit and Spock tests at the same time.

  • Spock uses the JUnit runner infrastructure and therefore is compatible with all existing Java infrastructure. For example, code coverage with Spock is possible in the same way as JUnit.

  • One of the killer features of Spock is the detail it gives when a test fails. JUnit mentions the expected and actual value, whereas Spock records the surrounding running environment, mentioning the intermediate results and allowing the developer to pinpoint the problem with greater ease than JUnit.

  • Spock can pave the way for full Groovy migration into a Java project if that’s what you want. Otherwise, it’s possible to keep your existing JUnit tests in place and use Spock only in new code.

  • Spock tests have the ability to include full English sentences in their code structures, allowing for easy documentation.


The first test


Java Class under test and JUnit test

SPOCK test for the Adder Java Class


The Second test

Multipler Class


A JUnit test for two Java classes


SPOCK test for two Java classes



SPOCK KNOWS ALL THE DETAILS WHEN A TEST FAILS


Failure of JUnit test in Eclipse


Failure of a SPOCK test in Eclipse



728x90

'오래된글 > Java' 카테고리의 다른 글

자바 nio - 1   (0) 2018.04.09
Java theory and practice: 웹 티어의 상태 복제  (0) 2018.04.09
Java Persistence with MyBatis 3  (0) 2018.04.09
Java performance tips-3  (0) 2018.04.09
Java performance tips-2  (0) 2018.04.09
Comments