2016년 4월 8일 금요일

Java Testing with SPOCK


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

댓글 없음:

댓글 쓰기

ETL 솔루션 환경

ETL 솔루션 환경 하둡은 대용량 데이터를 값싸고 빠르게 분석할 수 있는 길을 만들어줬다. 통계분석 엔진인 “R”역시 하둡 못지 않게 관심을 받고 있다. 빅데이터 역시 데이터라는 점을 볼때 분산처리와 분석 그 이전에 데이터 품질 등 데이...