gpt4 book ai didi

unit-testing - 从 SUnit 迁移到 Phexample

转载 作者:行者123 更新时间:2023-12-04 19:23:33 25 4
gpt4 key购买 nike

我正在试用 Pharo 的 Phexample我喜欢它,但是我的一半单元测试在 SUnit 中,另一半在 Phexample 中,感觉很笨拙。 Phexample 是否有我现有测试的导入功能?

最佳答案

关于期望匹配器,在 PhexMatcher 的类端有一系列重写规则。 .此截屏视频解释了如何使用 RB 的重写引擎:Code Critics in OB (OB Screencast 3) .

首先使用这些规则

RBParseTreeRewriter new
replace: 'self assert: [ `@expression ]' with: 'self assert: `@expression';
replace: 'self deny: `@expression' with: 'self assert: `@expression not';
yourself.

然后使用这些规则
RBParseTreeRewriter new
replace: 'self assert: `@value = `@expected' with: '`@value should = `@expected';
replace: 'self assert: `@value ~= `@expected' with: '`@value should not = `@expected';
replace: 'self assert: `@value > `@expected' with: '`@value should > `@expected';
replace: 'self assert: `@value < `@expected' with: '`@value should < `@expected';
replace: 'self assert: `@value >= `@expected' with: '`@value should >= `@expected';
replace: 'self assert: `@value <= `@expected' with: '`@value should <= `@expected';
replace: 'self assert: (`@value isKindOf: `@type)' with: '`@value should beKindOf: `@type';
replace: 'self assert: `@expression isNil' with: '`@expression should be isNil';
replace: 'self assert: `@expression notNil' with: '`@expression should be notNil';
replace: 'self assert: `@expression `test not' with: '`@expression should not be `test'
when: [:node | node arguments first receiver selector matchesRegex: '(is|has|not).+|atEnd' ];
replace: 'self assert: `@expression `test' with: '`@expression should be `test'
when: [:node | node arguments first selector matchesRegex: '(is|has|not).+|atEnd' ];
replace: 'self assert: (`@collection includes: `@element) not' with: '`@collection should not be includes: `@element';
replace: 'self assert: (`@collection includes: `@element)' with: '`@collection should be includes: `@element';
yourself.

关于引入测试之间的依赖关系,你必须手工重写你的测试。对于 JExample,有 JUnit2JExample但遗憾的是,Smalltalk 还没有自动迁移(目前)。

PS:如果您使用的是最新的 Pharo 镜像,则必须使用 OB 并恢复 OB-Refactory 包以使作用域重写规则起作用。只需执行
SystemBrowser default: OBSystemBrowserAdaptor.
Gofer new
wiresong: 'ob';
addPackage: 'OB-Refactory';
revert

关于unit-testing - 从 SUnit 迁移到 Phexample,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1769778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com