# MiniTest test case execution

**URL:** <https://www.ruby-forum.com/t/minitest-test-case-execution/191136>\
**Category:** Ruby\
**Created:** [July 6, 2010, 11:09am UTC](https://www.ruby-forum.com/t/minitest-test-case-execution/191136 "2010-07-06T11:09:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![george\_thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c77e96/32.png) [@george\_thomas](https://www.ruby-forum.com/u/george_thomas)\
**Post date:** [July 6, 2010, 11:09am UTC](https://www.ruby-forum.com/t/minitest-test-case-execution/191136/1 "2010-07-06T11:09:53Z")

</div>

Hi,

I have MiniTest derived class to run the test cases.

Its something as follows

class CustomClass \< MiniTest::Unit::TestCase  
def test1  
end  
def test2  
end  
…  
…  
def testn  
end  
end

My requirement is that if the logic inside test1 fails , I do not want  
to execute other tests. (test2 onwards)

(Calling exit , seem to be exiting from test1 only)

How can I do that?

Regards,  
George

---

<div class="post-metadata">

**Author:** ![george\_thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c77e96/32.png) [@george\_thomas](https://www.ruby-forum.com/u/george_thomas)\
**Post date:** [July 6, 2010, 2:54pm UTC](https://www.ruby-forum.com/t/minitest-test-case-execution/191136/2 "2010-07-06T14:54:22Z")

</div>

On Jul 6, 5:09 am, George T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end
> 
> How can I do that?

You can’t. The order of test execution is not guaranteed.

You might try putting test2+ in a separate file. You might alos just  
turn test1 into a conditional and only define test2+ if the condition  
passes. e.g.

if test1\_condition  
def test2  
…

---

<div class="post-metadata">

**Author:** ![george\_thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c77e96/32.png) [@george\_thomas](https://www.ruby-forum.com/u/george_thomas)\
**Post date:** [July 6, 2010, 3:34pm UTC](https://www.ruby-forum.com/t/minitest-test-case-execution/191136/3 "2010-07-06T15:34:47Z")

</div>

On 7/6/10, George T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end  
> …  
> …  
> def testn  
> end  
> end
> 
> My requirement is that if the logic inside test1 fails , I do not want  
> to execute other tests. (test2 onwards)
> 
> (Calling exit , seem to be exiting from test1 only)

Consider rewriting it like this: rename test1…testn to check1…checkn  
and write a toplevel test like this:

def test\_all\_of\_them  
test1  
test2  
…  
testn  
end

---

<div class="post-metadata">

**Author:** ![george\_thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c77e96/32.png) [@george\_thomas](https://www.ruby-forum.com/u/george_thomas)\
**Post date:** [July 7, 2010, 3:47pm UTC](https://www.ruby-forum.com/t/minitest-test-case-execution/191136/4 "2010-07-07T15:47:44Z")

</div>

Thanks for the reply.

I have found somewhere else in the forum that I can call a single test  
case  
as

Ruby --name test1

I will call , this from a batch file and store my info. in to a temp.  
text file (whether to call the rb file again without the --name argument  
or not)

I think the suggested solution by Caleb , is probably not suitable for  
me ,as I call assert from many of my test cases.

---

<div class="post-metadata">

**Author:** ![george\_thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c77e96/32.png) [@george\_thomas](https://www.ruby-forum.com/u/george_thomas)\
**Post date:** [July 9, 2010, 5:36am UTC](https://www.ruby-forum.com/t/minitest-test-case-execution/191136/5 "2010-07-09T05:36:57Z")

</div>

On 7/7/10, George T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I think the suggested solution by Caleb , is probably not suitable for  
> me ,as I call assert from many of my test cases.

And why does that matter? #assert is a method of TestCase, so it can  
be called from any other method of TestCase with no problem. You don’t  
have to always call it in methods whose names begin with ‘test\_’.
