从 SUnit 迁移到 Phexample

发布于 2024-08-12 02:57:27 字数 233 浏览 1 评论 0原文

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

I'm trying out Pharo's Phexample and I like it, but it feels clumsy to have half my unit tests in SUnit and the other half in Phexample. Does Phexample have like an import feature for my existing tests?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜唯美灬不弃 2024-08-19 02:57:27

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

Concerning the expectation matchers, there is a series of rewrite rules on the class side of PhexMatcher. This screencast explains how to use RB's rewrite engine: Code Critics in OB (OB Screencast 3).

First use these rules

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

Then use these rules

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.

Concerning the introduction of dependencies between test, you have to rewrite your tests by Hand. For JExample there is JUnit2JExample but alas there is not automagic migration for Smalltalk (yet).


PS: if you are using the latest Pharo image you must use OB and revert the OB-Refactory package to get scoped rewrite rules working. Just execute

SystemBrowser default: OBSystemBrowserAdaptor.
Gofer new
    wiresong: 'ob';
    addPackage: 'OB-Refactory';
    revert
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文