Ruby 单元测试将测试套件添加到已有的测试套件中

发布于 2024-09-12 03:57:02 字数 467 浏览 6 评论 0 原文

我有一个测试套件。我想添加另一个测试类,其中包含测试套件中的一组测试。由于这是一个带有测试用例的类,我不知道如何将其添加到测试套件中。

testsuite - 现有测试套件。
FactorTest.rb - 具有测试方法的测试类(类名称为 FactorTest )

我尝试过

testsuite<<FactorTest

Test::Unit::UI::Console::TestRunner.run(testuite)

但失败了:

/ruby/1.8/test/unit/testsuite.rb:54:in `size': undefined method `size' for
FactorTest:Class (NoMethodError) 

I have a test suite with me. I want to add another test class with a set of tests in the test suite. Since this is a class with test cases, I do not know how to add it to the test suite.

testsuite - existing test suite.
FactorTest.rb - test class with test methods (class name is FactorTest)

I tried

testsuite<<FactorTest

and then

Test::Unit::UI::Console::TestRunner.run(testuite)

but it fails:

/ruby/1.8/test/unit/testsuite.rb:54:in `size': undefined method `size' for
FactorTest:Class (NoMethodError) 

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

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

发布评论

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

评论(2

澜川若宁 2024-09-19 03:57:02

来自 http://www.ensta.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html

 require 'test/unit/testsuite'
 require 'tc_myfirsttests'
 require 'tc_moretestsbyme'
 require 'ts_anothersetoftests'

 class TS_MyTests
   def self.suite
     suite = Test::Unit::TestSuite.new
     suite << TC_MyFirstTests.suite
     suite << TC_MoreTestsByMe.suite
     suite << TS_AnotherSetOfTests.suite
     return suite
   end
 end
 Test::Unit::UI::Console::TestRunner.run(TS_MyTests)

From the docs at http://www.ensta.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html

 require 'test/unit/testsuite'
 require 'tc_myfirsttests'
 require 'tc_moretestsbyme'
 require 'ts_anothersetoftests'

 class TS_MyTests
   def self.suite
     suite = Test::Unit::TestSuite.new
     suite << TC_MyFirstTests.suite
     suite << TC_MoreTestsByMe.suite
     suite << TS_AnotherSetOfTests.suite
     return suite
   end
 end
 Test::Unit::UI::Console::TestRunner.run(TS_MyTests)
携余温的黄昏 2024-09-19 03:57:02

您可以重新打开 FactorTest 类并向其添加更多方法吗?

# In test file 1
class FactorTest < Test::Unit::TestCase
  def test_1
    assert true
  end
end

# In test file 2

class FactorTest < Test::Unit::TestCase
  def test_2
    assert true
  end
end

Could you just re-open the FactorTest class and add more methods to it?

# In test file 1
class FactorTest < Test::Unit::TestCase
  def test_1
    assert true
  end
end

# In test file 2

class FactorTest < Test::Unit::TestCase
  def test_2
    assert true
  end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文