问题标签 [midje]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
103 浏览

testing - midje 事实的动态计算描述

我想写一个函数来分解一些常见的事实,像这样

但这并没有导致“42 不奇怪”作为事实的描述。我知道使用表格事实可以实现类似的效果,但我希望能够在事实组之间分享这样的事实。

0 投票
2 回答
524 浏览

unit-testing - Why can't I use midje to mock a function that throws using slingshot's throw+

Here's the situation: I'm trying to unit test function A that calls function B. Function B is called in a slingshot try+ block and under certain circumstances it can throw using a slingshot throw+. I want to mock function B in a midje test so that it returns something that the catch in the try+ block will actually catch. I can't seem to create the right thing to throw though. Here's a substantially abbreviated sketch of the code and the test:

The ExceptionInfo that I'm throwing seems to be roughtly the right thing. I can see this when my application is running through numerous prn statements. However, whatever I try, I can't get the test to work.

I also tried the bit of code below in a repl to see whether I could understand the problem. However, whilst both pieces of code seem to involve identical Exceptions, only one (the pure slingshot one) manages to catch and print "caught it". I think that if I could understand why one works and the other doesn't, I would be able to solve the problem with the unit test.

0 投票
4 回答
4219 浏览

unit-testing - Clojure 单元测试:检查是否调用了函数

我正在尝试为我的 clojure 函数编写一些单元测试(我正在使用 clojure.test,但如果需要,我可以切换到 midje)。

我有一个函数,如下所示:

在对该功能进行单元测试时,我想编写以下测试用例:

如何断言调用了函数 generate-sky-nodes ?或不 ?我会在 C# 或 java 中使用模拟框架,但我不知道 clojure。

0 投票
1 回答
254 浏览

unit-testing - 测试文件系统代码

使用 Midje 进行单元测试是一种很棒的体验,但现在我需要测试一些与文件系统交互的代码。具体来说,代码从本地目录布局构建数据结构表示。

想到的是在 /tmp 中创建目录和文件,然后必须在测试后清理它们。我可能可以让它发挥作用,但如果有正确的方法来做到这一点会更好。

在 Clojure 或更一般的情况下,测试文件系统代码的首选方法是什么?

0 投票
0 回答
594 浏览

intellij-idea - leiningen midje 测试在 Intellij 中不起作用

考虑以下(最小的)leiningen 项目

./project.clj:

./repro/src/repro/core.clj:

./repro/test/repro/core_test.clj:

如果我安装了 leiningen midje 插件,它将在命令提示符下运行,如下所示:

但是,如果我将 leiningen 项目导入 Intellij 12.1.5 社区版,我会得到一个胖堆栈跟踪:

看起来 La Clojure + Intellij 找不到 midje 的一些先决条件,这很奇怪,因为 La Clojure 正在运行 leiningen.m2目录之外的类路径。

我一直在寻找 Intellij 的 midje 插件,但到目前为止还没有运气。

我需要这个,因为虽然我很高兴只使用 emacs + leiningen,但我的团队想要 Intellij。

0 投票
2 回答
936 浏览

clojure - Lein Midje:自动测试抛出异常(未找到命名空间)

我正在尝试为 midje 设置自动测试。目前,运行 lein midje 有效。然而,运行 lein midje :autottest 给了我下面的堆栈跟踪。

我遍历我的不同命名空间,它们都编译

0 投票
2 回答
773 浏览

unit-testing - Midje 中的模拟协议实现

有没有办法使用类似于“提供”的语法来模拟(不是存根)带有 Midje(clojure)的协议函数?

这类似于:Mocking Clojure 协议中的问题,但使用模拟。

更详细地说:我有一个协议和一个函数,它返回实现它的东西。我想对函数进行存根以返回协议的模拟,并且我想注册对模拟协议“实现”的功能之一的期望。

编辑 - 这是一个例子:

有一个协议及其实现:

有一个函数返回协议的实现:

TheThing可能是数据库或网络连接或您想在测试中摆脱的其他讨厌的东西。

然后,有我要测试的功能:

我想确保它用n调用go-bump

这是我第一次尝试创建测试。但这只是完成了一半,我想对 gimme 返回的Thiny设置期望

0 投票
1 回答
568 浏览

unit-testing - 如何在 clojure 中测试期货?

我正在尝试使用 midje 来测试未来,但我似乎无法让它发挥作用。

代码看起来像

像这样的测试

这失败了,说 bar 永远不会被调用。有什么办法吗?

0 投票
1 回答
309 浏览

clojure - 在 Clojure 和 Midje 中,如何编写间接调用的先决条件?

在下面的代码中,我想在实现 bar 函数之前测试 foo 函数。

但米杰说:

我认为“提供”不能挂钩 bar 函数,因为 foo 没有直接调用 bar。但我也发现如果我像这样更改第二行:

然后测试成功了。

第一个版本有什么方法可以成功吗?

谢谢。

PS:我正在使用 Clojure 1.5.1 和 Midje 1.5.1。

0 投票
1 回答
386 浏览

clojure - 使用 let 子句中提供的 midje 不会存根方法

当我使用外部 let 子句构建一些定义和调用进行测试时,存根无法按我预期的方式工作。例如:

此测试失败

使用此代码

我不应该对letmidje 使用语句吗?我无法理解如何在不删除let.