我正在尝试 Pharo 的Phexample,我喜欢它,但是在 SUnit 中进行一半的单元测试而在 Phexample 中进行另一半的单元测试感觉很笨拙。Phexample 对我现有的测试有类似的导入功能吗?
问问题
190 次
1 回答
5
关于期望匹配器,在类侧有一系列重写规则PhexMatcher
。此截屏视频解释了如何使用 RB 的重写引擎: OB 中的代码评论家(OB 截屏视频 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
于 2009-11-20T12:32:10.070 回答