从SUnit迁移到Phexample

gul*_*ver 5 unit-testing smalltalk pharo

我正在尝试Pharo的Phexample并且我喜欢它,但是在SUnit中进行一半单元测试而在Phexample中进行另一半测试感觉很笨拙.Phexample是否具有我现有测试的导入功能?

aku*_*uhn 5

关于期望匹配者,在课堂上有一系列重写规则PhexMatcher.此截屏视频介绍了如何使用RB的重写引擎:OB中的代码评论(OB Screencast 3).

首先使用这些规则

RBParseTreeRewriter new
    replace: 'self assert: [ `@expression ]' with: 'self assert: `@expression';
    replace: 'self deny: `@expression' with: 'self assert: `@expression not';
    yourself.
Run Code Online (Sandbox Code Playgroud)

然后使用这些规则

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.
Run Code Online (Sandbox Code Playgroud)

关于在测试之间引入依赖关系,您必须手动重写测试.对于JExample,有JUnit2JExample,但唉,还没有针对Smalltalk的自动迁移.


PS:如果您使用的是最新的Pharo映像,则必须使用OB并还原OB-Refactory包以使范围重写规则正常工作.只是执行

SystemBrowser default: OBSystemBrowserAdaptor.
Gofer new
    wiresong: 'ob';
    addPackage: 'OB-Refactory';
    revert
Run Code Online (Sandbox Code Playgroud)