我正在尝试Pharo的Phexample并且我喜欢它,但是在SUnit中进行一半单元测试而在Phexample中进行另一半测试感觉很笨拙。 Phexample是否具有我现有测试的导入功能?
答案 0 :(得分:5)
关于期望匹配者,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