spock

身为 Java 程序员必须掌握的 10 款开源工具

大兔子大兔子 提交于 2020-01-16 20:04:08
1. JIRA Atlassian 的JIRA是当前敏捷开发领域最重要的工具之一。它用于错误跟踪,问题跟踪和项目管理。如果你遵循敏捷开发方法,例如Sprint和Scrum,那么你必须了解JIRA。它允许您创建Spring循环并跟踪软件开发的进度。 JIRA 是目前比较流行的基于Java架构的管理系统,由于Atlassian公 司对很多开源项目实行免费提供缺陷跟踪服务,因此在开源领域,其认知度比其他的产品要高得多,而且易用性也好一些。 2. Git Git 是Java程序员的另一个必备工具,它是一个免费的开源分布式版本控制系统,旨在快速高效地处理从很小到非常大的项目版本管理。Git易于学习,占用空间小,具有超强的性能。 最初 Git 的开发是为了辅助 Linux 内核开发的过程,但是发现已经在很多其他自由软件项目中也使用了 Git。 3. Jenkins Jenkins 是一个用Java编写的开源自动化服务器。它有助于自动化软件开发,例如编译项目,运行单元测试,集成测试,生成文档以及在本地和远程存储库上载工件。主要用于: ● 持续、自动地构建/测试软件项目,如CruiseControl与DamageControl。 ● 监控一些定时执行的任务。 它是在项目中持续集成中最流行的工具之一。如果你还没有开始使用Jenkins,那就从现在开始吧。 4. Selenium Selenium

Grails + Mongodb + Spock: NullPointerException being thrown when doing embedded field query

耗尽温柔 提交于 2020-01-15 11:34:33
问题 On one service I'm trying to do something like: Organization.withCriteria { eq( "active", true ) eq( "location.region", region) } which is working but when calling the method inside a unit test I get: java.lang.NullPointerException at org.grails.datastore.mapping.keyvalue.mapping.config.KeyValuePersistentEntity.getPropertyByName(KeyValuePersistentEntity.java:75) at grails.gorm.CriteriaBuilder.validatePropertyName(CriteriaBuilder.java:954) at grails.gorm.CriteriaBuilder.eq(CriteriaBuilder.java

Grails + Mongodb + Spock: NullPointerException being thrown when doing embedded field query

谁都会走 提交于 2020-01-15 11:34:05
问题 On one service I'm trying to do something like: Organization.withCriteria { eq( "active", true ) eq( "location.region", region) } which is working but when calling the method inside a unit test I get: java.lang.NullPointerException at org.grails.datastore.mapping.keyvalue.mapping.config.KeyValuePersistentEntity.getPropertyByName(KeyValuePersistentEntity.java:75) at grails.gorm.CriteriaBuilder.validatePropertyName(CriteriaBuilder.java:954) at grails.gorm.CriteriaBuilder.eq(CriteriaBuilder.java

Karate vs Spock

不问归期 提交于 2020-01-13 18:58:50
问题 I've recently found Karate framework for testing Web Services. But there is also Spock framework providing similar ( to my mind ) functionality. What are the differences between the frameworks? I would like to suggest our testers to take a look at it. 回答1: Developer of Karate here. I have only read about Spock but here's my PoV. Karate is laser-focused on testing HTTP web-services, and therefore is designed to manipulate and perform assertions on JSON and XML. As a result - you do not need

How to refactor common Geb test sequences

浪子不回头ぞ 提交于 2020-01-11 09:41:29
问题 Suppose I have multiple Geb/Spock tests that beings with logging in. For example: @Stepwise Class AddNewPictureSpec extends GebSpec { def "User at login page"() { given: "User beings from login page" to LoginPage } def "User gets redirected to Main page"() { given: "User at Login page" at LoginPage when: "User signs in" signIn "username", "pw" to MainPage then: at MainPage def "other test sequences follow...."() { } } And another test spec with the exact same start sequence: @Stepwise Class

Unit testing of a class with StaticLoggerBinder

别说谁变了你拦得住时间么 提交于 2020-01-10 01:23:27
问题 I do have a simple class like this: package com.example.howtomocktest import groovy.util.logging.Slf4j import java.nio.channels.NotYetBoundException @Slf4j class ErrorLogger { static void handleExceptions(Closure closure) { try { closure() }catch (UnsupportedOperationException|NotYetBoundException ex) { log.error ex.message } catch (Exception ex) { log.error 'Processing exception {}', ex } } } And I would like to write a test for it, here is a skeleton: package com.example.howtomocktest

Spock-Groovy实战

血红的双手。 提交于 2020-01-08 21:16:23
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 前言 之前写单测都是用mockito然后基于java来写单测,但是操作下来写单测确实很占用时间,而且有时候为了提高条件覆盖率,需要写大量的代码,那么该咋办呢? 经过小伙伴的推荐,我去试了下Spock + Groovy,果然很好用,所以在这里特地记下来。 操作 那就不多废话了,如果想了解Spock理论知识的可以自行google一波。 安装Groovy环境 官网地址: http://www.groovy-lang.org/download.html 找一个自己喜欢的路径将他下载下来并解压 配置环境变量 vi ~/.bash_profile 加入如下配置 # groovy export GROOVY_PATH=/Users/***/groovy/groovy-2.5.8/bin export PATH=$PATH:$GROOVY_PATH 验证 groovy -v 这样的话Groovy环境就ok啦! 新建groovy目录 接下去就自己新建路径,然后new Groovy Class即可 注意点: 如果想要统计覆盖率的话,记得要在idea中配置插件,如下: 写法 基本的语法大家可以自行查找一波,可以看W3C school。地址: https://www.w3cschool.cn/groovy/

Spring/Spock - integration test of authentication

家住魔仙堡 提交于 2020-01-05 05:31:10
问题 I want to test protected endpoints in my application and I would like login before each test, get token and use this token in next tests. @ContextConfiguration @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @Stepwise class IntegrationSpec extends Specification { @Autowired private TestRestTemplate rest @Autowired private String token @Shared private HttpEntity request def setup() { UserData userData = new UserData("Username", "Password"); def response = rest

Throw/Catch Exception in Groovy

做~自己de王妃 提交于 2020-01-05 03:39:17
问题 I am new to Groovy and trying to implement Spock framework in my application. Here is my test code: def "Test class with mock object"() { setup: SomeObject sp = Mock() test= TestClass() when: System.out.println('comes here'); push.exec(sp) then: sp.length == 1 } Here TestClass is throwing some exception which I have to catch in test method or throw it again. I tried try { push.exec(sp) } catch (Exception e) { } But still getting groovy.lang.MissingMethodException: No signature of method: test

Spock unit testing assert log calls and see output

女生的网名这么多〃 提交于 2020-01-05 03:06:19
问题 I am using spock to test Java Spring Boot code. It gets a logback logger over the lombok @Slf4j annotation. Dummy class with log call import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @Slf4j @Component public class Clazz { public void method() { // ... code log.warn("message", new RuntimeException()); } } The Spock Spec import groovy.util.logging.Slf4j import org.junit.Rule import org.slf4j.Logger import spock.lang.Specification @Slf4j class LogSpec extends