【问题标题】:Migrating from SUnit to Phexample从 SUnit 迁移到 Phexample
【发布时间】:2009-11-20 11:07:45
【问题描述】:

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

【问题讨论】:

    标签: unit-testing smalltalk pharo


    【解决方案1】:

    关于期望匹配器,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
    

    【讨论】:

    • 太酷了!我希望所有库都提供重写规则:)
    猜你喜欢
    • 1970-01-01
    • 2012-12-04
    • 2011-04-26
    • 2015-07-23
    • 2020-05-31
    • 2010-10-26
    • 2022-01-14
    • 2016-09-27
    • 2011-04-29
    相关资源
    最近更新 更多