- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为具有.class参数的方法编写单元测试。
例如:
ExampleService {
def myExample(clazz){
//do stuff and return some object
}
}
/* How the above function gets used */
AnotherExampleService extends exampleService {
def blah() {
def obj = myExample(AnotherClass.class)
}
}
/* Now I need to test the above blah() function */
AnotherExampleServiceSpec extends Specification {
def "test blah"() {
//The following doesn't seem to work
ExampleService.metaClass.myExample = { def arg1 -> obj }
}
}
最佳答案
我可能会在测试中将ExampleService子类化。所以它看起来像:
ExampleService {
def myExample(clazz){
//do stuff and return some object
}
}
AnotherExampleService extends ExampleService {
def exampleService
def blah() {
def obj = myExample(AnotherClass)
}
}
AnotherExampleServiceSpec extends Specification {
def "test blah"() {
given:
AnotherExampleService service = new AnotherExampleService() {
@Override
def myExample(clazz){
//whatever you want to do
return whatEverResult
}
when:
def result = service.blah (SomeClass)
then:
result
}
}
def myExample(Class clazz)
。
关于unit-testing - 如何模拟一种在clazz中传递的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31330632/
构建中断后,一位开发人员提示说这是因为以前可用的 Clazz.clone()(不是类的真实名称 :))已被删除,所以他调用 clz.clone() 正在中断。 据此Clazz 的作者建议将客户端代码更
我有两个作用于 Clazz 类型对象的函数,它们之间的唯一区别是我访问其成员的方式: void foo(vector& v) { ... v[0]->method(); ...
我需要在 java 中使用反射。我明白 Class clazz创建一个代表 Class 的变量目的。但是,我正在尝试引用 Class来自 String 的对象使用 forName("aClassNam
我正在研究 Snappy、Zlib 等的压缩器实现(Java 中)。靠近源文件顶部的是下面的这一行。谁能给我解释一下这是什么意思? HACK - Use this as a global lock i
所以我知道 Python 的 typing.Optional。但是我自己编写了粗略的 PyOptional(代码 here )并想将 Optional[T] 与我的 PyOptional 结合到 Py
我需要一些关于简单正则表达式的帮助。目标是简化 Java 方法的参数。 输入:java.util.Locale arg0, java.lang.String arg1, java.lang.Objec
我正在尝试调用 EasyMock.isA(Class)在 List 上.有没有办法在没有警告的情况下做到这一点? 我试过以下方法: isA(List.class); // doesn't compi
如何Class clazz看起来像 Kotlin ? 我正在尝试将此方法转换为 Kotlin 代码,但似乎卡住了。 public static boolean isServiceRunning(Con
我已经开发 Android 应用程序大约 1 个月了,现在我已经非常熟悉 Java 语法了,但今天我偶然发现了这段代码: try { Class clazz =
我必须为 GWT/GXT 项目开发一个“通用”wigdet,为此我需要创建一个类型未知的对象实例。我找到了一种在开发模式下完美运行的方法,但是当我尝试编译我的项目并部署它时,我得到了一个 Only c
我有一个 WifiScanning 类: public class WifiScanning extends AbstractSetting { /** * */ private static f
我尝试使用 JAXB 将 XML(String) 解析为对象,但我找不到调用我创建的方法的方法,因为我不知道如何指定类 BasicRequest与 SomeRequest如G public class
我在 Spring 中有一个 bean 定义,它是代理对应物,可以在任何地方使用: someInterceptor 一切正常;在
在我的测试中,我有以下行: when(client.runTask(anyString(), anyString(), isA(Iterable.class)).thenReturn(...) isA
我一直在与 Java 泛型作斗争,这就是我正在尝试做的事情: ... sortedActions = new ArrayList(); ActionGroup actionGroup = null;
我想通过 method.invoke(clazz, varargs) 使用反射来使用不同数量的参数进行方法调用,并通过这种方式实现仅一次调用即可调用不同的方法,而不是通过显式的、硬编码的参数数量。目前
我希望能够检查 session 是否包含给定类/标识符的实体。我目前看不到执行此操作的方法。 contains() 接受一个实体对象而不是类+键 get() 如果实体不存在则查询数据库,这是我不想做的
我正在尝试在我的 JBoss EAP 服务器容器中运行 Arquillian 测试。当我运行它们时,我收到以下信息消息: 16:49:48,648 INFO [org.jboss.weld.Clas
这看起来很简单,但我很难找到答案。我在一个类上使用 getDeclaredFields() ,对于某些字段,它返回 Set 而不是集合中的 Class。 for(Field f: clazz.
我有一个接受泛型的类 public class Publisher { ... } 扩展 Storable 的类的对象可以被“发布”(由此类处理)。 在构造函数中,我还获得了有关此实例如果 P
我是一名优秀的程序员,十分优秀!