- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Spock 的新手,尝试编写一个简单的 Spock 但失败了:
Error:Groovyc: Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:.../.m2/repository/org/spockframework/spock-core/1.0-groovy-2.4/spock-core-1.0-groovy-2.4.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation because of exception java.lang.NullPointerException
这是我的规范:
@Unroll
class UserFilterSpec extends Specification {
private static final String USER_ID_1 = "someUserId1";
private static final String USER_ID_2 = "someUserId2";
private static final String USER_ID_3 = "someUserId3";
def filter = new UserFilter()
def User user1 = setupTestUser(USER_ID_1)
def User user2 = setupTestUser(USER_ID_2)
def User user3 = setupTestUser(USER_ID_3)
def "given a list of users and list of user ids, should return list of user with those users removed"() {
expect:
filter.filterUserDataByIds(userList, userIdList) == filterList
where:
userList | userIdList || filterList
Lists.newArrayList(user1, user2, user3) | Lists.newArrayList(USER_ID_1) || Lists.newArrayList(user2, user3)
}
}
这是我的 pom.xml:
<!-- Mandatory plugins for using Spock -->
<plugin>
<!-- The gmavenplus plugin is used to compile Groovy code. To learn more about this plugin,
visit https://github.com/groovy/GMavenPlus/wiki -->
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Optional plugins for using Spock -->
<!-- Only required if names of spec classes don't match default Surefire patterns (`*Test` etc.) -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<useFile>false</useFile>
<includes>
<include>**/*Spec.java</include>
<include>**/*Test.java</include> <!-- Just in case of having also "normal" JUnit tests -->
</includes>
</configuration>
</plugin>
...
<!-- Mandatory dependencies for using Spock -->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.0-groovy-2.4</version>
<scope>test</scope>
</dependency>
<!-- Optional dependencies for using Spock -->
<dependency> <!-- use a specific Groovy version rather than the one specified by spock-core -->
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.1</version>
</dependency>
<dependency> <!-- enables mocking of classes (in addition to interfaces) -->
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.1</version>
<scope>test</scope>
</dependency>
<dependency> <!-- enables mocking of classes without default constructor (together with CGLIB) -->
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
我的 Spec 或 pom 设置有什么问题?我必须安装 Groovy 才能使其工作吗?
最佳答案
这是您的测试,用更惯用的 Spock/Groovy 重写:
@Unroll
class UserFilterSpec extends Specification {
static final String USER_ID_1 = "someUserId1"
static final String USER_ID_2 = "someUserId2"
static final String USER_ID_3 = "someUserId3"
@Shared user1 = setupTestUser(USER_ID_1)
@Shared user2 = setupTestUser(USER_ID_2)
@Shared user3 = setupTestUser(USER_ID_3)
@Shared filter = new UserFilter()
def "given a list of users and list of user ids, should return list of user with those users removed"() {
expect:
filter.filterUserDataByIds(userList, userIdList) == filterList
where:
userList | userIdList || filterList
[user1, user2, user3] | [USER_ID_1] || [user2, user3]
}
}
一些注意事项:
[user1, user3]
而不是 Lists.newArrayList
。@Shared
或 static
是测试中使用的类级变量所必需的。这将解决您的编译问题。关于java - 斯波克错误 :Groovyc: Could not instantiate global transform class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40326406/
我正在编译一个项目,该项目在 Eclipse 中运行良好,并使用 ant 构建良好,但在 IntelliJ IDEA 中给出: 内部 groovyc 错误:代码 1 我该如何解决这个问题?其他错误消息
我正在尝试使用 Groovy,特别是从 Java 应用程序中编译和运行 Groovy 类。 当然,Groovy 可能存在编译问题,并且我看到有关报告编译问题的不同行为 - 在命令行上运行 groovy
我有一些 groovy 文件,我用 groovyc 编译成 java 类文件(因为启动 java 比启动 groovy 只是为了运行一个简短的脚本要快一点。)所有脚本都在默认包中,但是它们共享“.su
在 maven 或 gradle 中设置一个混合的 java7/groovy2 项目时,是否有任何理由先用 javac 然后用 groovyc 编译,而不是让 groovyc 处理所有的事情? 我开始
当我在没有 fork 选项的情况下运行 groovyc 时,它工作得很好。但使用 fork="true"时会失败并显示错误消息: Error: Could not find or load main
嗨,我有一组 java 类,当我使用 javac 命令编译它们时,它们工作得非常好: javac -g -nowarn -classpath /usr/class/cs143/cool/lib:.:/
我正在尝试编译一个项目,其中有一些用 groovy 编写的测试。该项目具有适用于 Java 12 的 --enable-preview。 我正在使用 gmavenplus-plugin 来做到这一点:
我是 Spock 的新手,尝试编写一个简单的 Spock 但失败了: Error:Groovyc: Could not instantiate global transform class org.s
我在 Intellij Idea 中有一个 gradle 项目,其中包含两个模块: foo-core |--src | |--main | | |--java
我在 Ubuntu 18.04 下安装了 Netbeans 11.3,并在下面创建了一个新的 Groovy 项目。 从主菜单中选择"file">“新建项目”(Ctrl-Shift-N;在 Mac 上为
我有 Java 经验,但对 Groovy 还很陌生。另外,我习惯在 Eclipse 中完成 Java 工作,但有人要求我切换到 IntelliJ,所以我就这么做了。我继承的项目是从 GitHub 存储
我正在尝试在所有 Java、Groovy 和 Kotlin 之间进行联合/混合编译。我目前正在研究一个理论,即如果可以让 groovyc 只在第一阶段发出 stub 文件,那应该是可能的。 可以吗?否
我正在使用 IntelliJ 11.1.3、IvyIDEA Plugin for IntelliJ、Spock 0.5(这取决于 Groovy 1.8.4 ) 和 Groovy 1.5.6。 我有一个
我是一名优秀的程序员,十分优秀!