有QuickCheck Happstack.State方法的好方法吗? [英] Is there a good way to QuickCheck Happstack.State methods?
问题描述
我有一套我想用QuickCheck测试的Happstack.State MACID方法,但是我很难找出最优雅的方法来实现这一点。我遇到的问题是:
- 评估
Ev
monad计算位于IO
monad中,通过query
或update
。 - 无法创建纯粹的内存中MACID存储; 这是通过设计。因此,在
IO
monad中运行的东西意味着每次测试后都有临时文件需要清理。 无法初始化a除了initialValue
以外的新MACID存储;它不能通过任意
生成,除非我公开一个取代批发状态的访问方法。 - 解决上述所有问题表示仅使用
MonadReader
或MonadState
特性的函数(并在Reader中运行测试) 或
State
而不是Ev
,这意味着放弃使用getRandom
或getEventClockTime
等方法定义内部。
我可以看到的唯一选项是:
initialValue
开始建立。
MonadReader
或 MonadState
(它更容易测试),并且依靠少量不能快速检查的胶水它调用 getRandom
或 getE如果需要,可以使用ventClockTime
。
有没有更好的解决方案,我可以忽略它?
$$ b
您可以检出happstack-state附带的quickcheck属性: http: //patch-tag.com/r/mae/happstack/snapshot/current/content/pretty/happstack-state/tests/Happstack/State/Tests
如果您只是在进行测试,并且您想要一个可抛弃的数据存储,那么您可以使用内存保存程序,它只将状态,事件文件和检查点存储在RAM中。如果你失去了力量,那么你的所有状态都会丢失。这对测试来说很好,但不适用于真实的现场服务器。您链接的信息是关于真实的在线服务器,而不仅仅是测试。
这对initialValue问题没有帮助,但它确实使选项1更容易,因为您不必进行任何磁盘清理。
要替换initialValue,您需要创建自己的方法来取代当前批发状态。
类似于:
newState :: YourState - >更新YourState()
newState st = put st
或其他东西。
- jeremy
I have a set of Happstack.State MACID methods that I want to test using QuickCheck, but I'm having trouble figuring out the most elegant way to accomplish that. The problems I'm running into are:
- The only way to evaluate an
Ev
monad computation is in theIO
monad viaquery
orupdate
. - There's no way to create a purely in-memory MACID store; this is by design. Therefore, running things in the
IO
monad means there are temporary files to clean up after each test. - There's no way to initialize a new MACID store except with the
initialValue
for the state; it can't be generated viaArbitrary
unless I expose an access method that replaces the state wholesale. - Working around all of the above means writing methods that only use features of
MonadReader
orMonadState
(and running the test insideReader
orState
instead ofEv
. This means forgoing the use ofgetRandom
orgetEventClockTime
and the like inside the method definitions.
The only options I can see are:
- Run the methods in a throw-away on-disk MACID store, cleaning up after each test and settling for starting from
initialValue
each time. - Write the methods to have most of the code run in a
MonadReader
orMonadState
(which is more easily testable), and rely on a small amount of non-QuickCheck-able glue around it that callsgetRandom
orgetEventClockTime
as necessary.
Is there a better solution that I'm overlooking?
You might checkout out the quickcheck properties that are included with happstack-state:
If you are just doing testing, and you want a throw-away data store, then you can use the memory saver, which just stores the state, event files, and checkpoints in RAM. If you lose power, then all your state would be lost. That is fine for tests, but not for a real live server. That message you linked to was talk about real live servers, not just testing.
That won't help with the initialValue issue, but it does make option 1 easier since you don't have to do any disk cleanup.
To replace the initialValue, you would need to create your own method that replaces the current state wholesale.
something like:
newState :: YourState -> Update YourState () newState st = put st
or something.
- jeremy
这篇关于有QuickCheck Happstack.State方法的好方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!