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

댓글 없음:

댓글 쓰기

시스템 부팅시 도커 컨테이너 자동 실행

Docker 컨테이너를 운용중인 시스템이 Reboot 되버리면 컨테이너가 자동으로 올라오지 않아 불편해서 시스템 리붓시 컨테이너를 자동으로 시작되게 init 데몬에 등록하기로 했습니다. 서버는 Ubuntu 17.10 Docker는 17.0...