Wren 赛道上的测试

了解如何在 Exercism 上测试你的 Wren 练习


运行测试:

$ wrenc exercise-name.spec.wren

例如hello-world:

$ wrenc hello-world.spec.wren

理解跳过测试

skip方法会让测试套件不运行某个测试。

  • 为什么要跳过?

这样可以让你一次专注于一个测试,并在逐步完善解答的过程中把它们逐个启用。

  • 如何启用?

一个被跳过的测试:

// this test will be skipped and not run
skip.test("title cased phrases") {
    Expect.value(Acronyms.parse("Portable Network Graphics")).toEqual("PNG")
}

只需把skip.test改成do.test。

// now the test will be run normally
do.test("title cased phrases") {
    Expect.value(Acronyms.parse("Portable Network Graphics")).toEqual("PNG")
}

创建你的第一个 Wren 模块

这条学习路径上的测试会以 Wren 模块的形式导入你的实现来加载它:import "./bob" for Bob。导出实现不需要任何特殊语法。只要把你的类命名为Bob,与for Bob这条导入语句保持一致,一切就能正常工作。

class Bob {
  static hey(message) {
    // Your solution to the exercise goes here
  }
}

关于模块的更多信息,可以查阅 Wren 模块化文档。 为了方便你上手,每个练习的目录里都有一个 骨架 Wren 文件。