how to call a method immediately before the start of a test run in minitest

dax

I have the following scenario in testing a large, distributed system via end-to-end tests:

Class A < Minitest::Spec

  before do 
    # stuff

    setup_runtime_environment
  end

end

Class B < Class A

  before do 
    # stuff
  end

end

Class C < Class B

  before do 
    # stuff
  end

end

Some tests only inherit from Class A - it is the most general and includes things which are relevant to testing the entire system.

Class B is more specific - it includes things which are relevant to a large group of tests, but still needs to be setup by the setup_runtime_environment method in Class A

Class C is the most specific - it includes things which are relevant only to a small group of tests, but still needs to be setup by the setup_runtime_environment method in Class A

The problem is that the runtime environment, for various test purposes, needs to be configured differently when running 'overall' tests vs. 'general' tests vs. 'specific' tests, and it needs to be configured before it is initialized.

So I could add the setup_runtime_environment method to the end of each before block. But more ideal would be a way to run that method immediately before the specs are run. A 'just_before' block. Does anyone know of a way to do this?

To clarify:

If I'm running an 'overall' spec - one that inherits only from Class A, the stack looks something like this, assuming 'A' is the before block in Class A and 's' is setup_runtime_environment:

A -> s -> running of specs

Likewise if I'm running a specific spec - one that inherits from Class C, the stack would look something like this:

A -> s -> B -> C -> running of specs

I want 's' to be called at the very end of any chain:

A -> s -> running of specs  

or

A -> B -> s -> running of specs  

or

A -> B -> C -> s -> running of specs  

which is what I mean by 'just before' - as in just before the specs are run.

blowmage

You are limited because of the behavior of the spec DSL. If you want to really control when your setup code is run along with the inherited setup, you should use the test-style setup and super.

Class A < Minitest::Spec

  def setup
    # do stuff
    setup_runtime_environment
  end

end

Class B < Class A

  def setup
    super
    # do stuff after setup_runtime_environment
  end

end

Class C < Class B

  def setup
    # do stuff before setup_runtime_environment
    super
  end

end

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to start a docker container before run the test

How to test a method is called with Minitest?

Test helper method with Minitest

How do you test code that is run Immediately?

Is it possible to run a single test in MiniTest?

How to run method in test

How to set a default value for a method call in a instance with minitest?

Minitest - How do you test a method isn't invoked?

how do I test a private method on controller, using minitest?

How to test a controller's update method in Rails using minitest?

JMeter method call on start/end of test plan

start() doesn't call run() method

I want to call def setup method before all tests in minitest ruby

How to start mysqld and then run query immediately from command line?

How to start Windows Terminal and run git bash command immediately?

How to call a method and run it asynchronously?

How to run tests before start ring server

How to use Spring AOP to run code before every call of service method in Servlet

How to run some code before each JUnit @Test method individually, without using @RunWith nor AOP?

How should I run the same test case without running the @before method from TestNG?

Cucumber 7 + TestNG - Dynamic tags manipulation before test run start

How to test rake task in Minitest?

How to get test summary in Minitest?

Java - Call to start method on thread : how does it route to Runnable interface's run ()?

How run() method is getting invoked when I call Thread.start()?

How to run code before ApplicationRunner in a unit test?

How to run a setup before all test suites?

How to stub a method with argument in MiniTest

How to fake a method in Rails Minitest