Tag: testunit

如何在ruby模块中包含unit testing?

我正在尝试将模块的unit testing包含在与模块本身相同的源文件中,遵循Perl modulino模型。 #! /usr/bin/env ruby require ‘test/unit’ module Modulino def modulino_function return 0 end end class ModulinoTest < Test::Unit::TestCase include Modulino def test_modulino_function assert_equal(0, modulino_function) end end 现在,我可以运行执行此源文件的unit testing。 但是 ,当我需要/从另一个脚本加载它们时,它们也会运行。 如何避免这种情况? 有没有更惯用的方法来实现这一点,除非这种做法不鼓励?

在Ruby中,如何控制Test :: Unit测试的运行顺序?

例如,运行这些测试时,我想确保test_fizz始终先运行。 require ‘test/unit’ class FooTest < Test::Unit::TestCase def test_fizz puts "Running fizz" assert true end def test_bar puts "Running bar" assert true end end 更新 :我为什么要这样做? 我的想法是某些测试的早期失败(那些测试更简单,更基本的方法)将使得更容易追踪系统中的问题。 例如, bar的成功取决于fizz正常工作。 如果fizz被打破了,我想知道这一点,因为没有必要担心bar ,它也会失败,但测试结果的输出要复杂得多。

如何输出rubyunit testing的名称

我有一个unit testing(例子是修改Test :: Unit文档 ) require ‘test/unit’ class TC_MyTest < Test::Unit::TestCase def test_something assert(true) end end 当我执行它时,我得到: Loaded suite C:/test Started . Finished in 0.0 seconds. 1 tests, 1 assertions, 0 failures, 0 errors 我想得到这样的东西( test_something输出): Loaded suite C:/test Started test_something . Finished in 0.0 seconds. 1 tests, 1 assertions, 0 failures, 0 errors

在Ruby的Test :: Unit :: TestCase中,如何覆盖initialize方法?

我正在与Test :: Unit挣扎。 当我想到unit testing时,我想到了每个文件的一个简单测试。 但是在Ruby的框架中,我必须改为: class MyTest < Test::Unit::TestCase def setup end def test_1 end def test_1 end end 但是每次调用test_ *方法都会运行setup和teardown。 这正是我不想要的。 相反,我想要一个只为整个类运行一次的设置方法。 但我似乎无法在不破坏TestCase的初始化的情况下编写自己的initialize()。 那可能吗? 还是我让这绝望地变得复杂?