Hey folks,
I've been trying my best to write a class that uses initialize() with
minitest, so that I can swap out a specific dependency at runtime. It
appears, though, that I cannot use initialize() in a class that inherits
from minitest:
#####
require "minitest/autorun"
#A simple dependency which is being dispatched to.
class Dependency
def initialize(argument)
$stderr.puts argument
end
end
#The main test class.
class TestProblemReproduction < MiniTest::Unit::TestCase
def initialize(test_argument)
Dependency.new(test_argument)
end
def test_something
puts "This is here so minitest does something."
end
end
TestProblemReproduction.new("stuff")
#######
Expected Output is to see the class Dependency output "stuff".
The actual output is that the class Dependency outputs
"stuff\ntest_something"
However, I have a use case where I would like to use minitest to run my
test cases, but I have a bunch of tests written in selenium. With one
flag,
the selenium browser will be constructed to run locally on my desktop,
for
local testing. With a different flag, the selenium browser is
constructed
to run remotely on a set of remote test servers.
Is there any way I can hand a dependency into my minitest based test
cases?
Or do they have to be static?
Thanks!
Jams
on 2013-03-08 00:04
on 2013-03-08 00:22
Hi folks, as an addendum, this problem is preset for me because I'm using minitest/autorun. I wanted to use this because of the various hooks that are provided (def setup() etc); if you can think of a way to provide the same pre-test hooks without being tied in to autorun, I could use that instead. Jams
on 2013-03-08 02:15
On Mar 7, 2013, at 15:02 , James Harrison <jam@jamandbees.net> wrote: > $stderr.puts argument > puts "This is here so minitest does something." > end > end > > > TestProblemReproduction.new("stuff") > > ####### > > Expected Output is to see the class Dependency output "stuff". > The actual output is that the class Dependency outputs "stuff\ntest_something" The #1 rule of OO is if you override a method you NEED to call super. The #2 rule of OO is if you override a method you NEED to make sure it conforms to the contract. You're breaking both these rules. #initialize is defined on TestCase, and it takes an arg which is the name of the test being run. > However, I have a use case where I would like to use minitest to run my test cases, but I have a bunch of tests written in selenium. With one flag, the selenium browser will be constructed to run locally on my desktop, for local testing. With a different flag, the selenium browser is constructed to run remotely on a set of remote test servers. > > Is there any way I can hand a dependency into my minitest based test cases? Or do they have to be static? There is nothing static about minitest. I don't see why you need to do this via initialize/new tho, so I'm guessing I don't understand the problem well enough. You shouldn't be instantiating TestCase instances. That's the runner's job.
on 2013-03-08 02:16
On Mar 7, 2013, at 15:22 , James Harrison <jam@jamandbees.net> wrote:
> as an addendum, this problem is preset for me because I'm using
minitest/autorun. I wanted to use this because of the various hooks that are
provided (def setup() etc); if you can think of a way to provide the same pre-test
hooks without being tied in to autorun, I could use that instead.
autorun is orthogonal to TestCase, so again... I don't understand the
problem well enough to help.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.