Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip certain tests with Test::Unit

In one of my projects I need to collaborate with several backend systems. Some of them somewhat lacks in documentation, and partly therefore I have some test code that interact with some test servers just to see everything works as expected. However, accessing these servers is quite slow, and therefore I do not want to run these tests every time I run my test suite.

My question is how to deal with a situation where you want to skip certain tests. Currently I use an environment variable 'BACKEND_TEST' and a conditional statement which checks if the variable is set for each test I would like to skip. But sometimes I would like to skip all tests in a test file without having to add an extra row to the beginning of each test.

The tests which have to interact with the test servers are not many, as I use flexmock in other situations. However, you can't mock yourself away from reality.

As you can see from this question's title, I'm using Test::Unit. Additionally, if it makes any difference, the project is a Rails project.

like image 920
Daniel Abrahamsson Avatar asked May 28 '10 07:05

Daniel Abrahamsson


People also ask

How do you skip a unit test?

test. skip=true to skip the entire unit test. By default, when building project, Maven will run the entire unit tests automatically.

Can we skip unit testing?

However, writing them takes time, and since you can deliver an application without unit tests, some entrepreneurs unwisely consider them unnecessary.

How do I skip a test in Pytest?

The simplest way to skip a test is to mark it with the skip decorator which may be passed an optional reason . It is also possible to skip imperatively during test execution or setup by calling the pytest. skip(reason) function. This is useful when it is not possible to evaluate the skip condition during import time.


2 Answers

New Features Of Test Unit 2.x suggests that test-unit 2.x (the gem version, not the ruby 1.8 standard library) allows you to omit tests.

like image 74
Andrew Grimm Avatar answered Oct 06 '22 12:10

Andrew Grimm


The features referred to in the previous answer include the omit() method and omit_if()

def test_omission
  omit('Reason')
  # Not reached here
end

And

def test_omission
  omit_if("".empty?)
  # Not reached here
end

From: http://test-unit.rubyforge.org/test-unit/en/Test/Unit/TestCaseOmissionSupport.html#omit-instance_method

like image 34
Ross Attrill Avatar answered Oct 06 '22 11:10

Ross Attrill