Why Grails unit, integration and functional test phases do not have their own environment? - grails

Unit test don't need a database.
Integration and functional tests can have different fixtures and bootstrap data.
It would be also better to split functional tests on application itself and Selenium testing robot.
So, is there any reason to keep all tests phases in one environment?

I guess that's just a convention, since:
The setup of the unit tests configure a memory database to let you use GORM methods.
Your database will be initialized only when running integration tests.
Functional tests are treated as extension and depending on your project they're not mandated (for example: plugin projects that does not rely on UI).
Nothing stops you to define custom environments and run specific commands to them. You can also create Spring Beans and configure database access according to your env, using the Environment class.
if(Environment.current == Environment.DEVELOPMENT) {
...
}

Related

System tests VS integration tests Rails 5.1?

Before upgrading to rails 5.1 i test my rails app via integration tests. And 70% of my rails app is automated via integration tests. Means all of application simple and complex behaviors are automated via integration tests. Off-course rails did not provided any java-script based testing.
With Arrival of Rails 5.1 they include system tests and said that every app interact with java-script and now you can test your app end to end scenarios like a real user interacting with browser. So my manager ask me to move all integration tests to system tests. Ok good! we can test our application the way our users experience it and help us test JavaScript as well.
Definitely system test can cover almost all integration tests as well. So whats the importance of integration testing now ?
Why should someone write integration test in Rails 5.1 when he can
write same test case in System test?
Thanks in advance.
I wonder the same, but from this I get the impression that system tests will replace integration testing - however, the only drawback seems to be speed and resource usage.

How to configure Rails to run custom tests?

I'm using Sidekiq for background jobs.
Sidekiq offers the opportunity to test your code inside its workers, rb files in app/workers
My code scrapes data from external websites and updates the database.
To test it with Minitest Unit, I thought I could create a test/workers directory and insert there my tests, that could inherit directly from Minitest::Test if this could work.
In fact, none of my tests, except one that can be defined as integration test, would test models, controllers, mailers or can be defined as integration tests.
My question is whether will I be able to run these tests (or my entire test suite included Sidekiq's tests) with either one of the following commands:
rails test:workers
rails test
or am I expected to extend somehow (how?) rake test configuration?
From which one of the following class would be better my test inherit from?
ActiveSupport::TestCase
Minitest::Test

How to tell RSpec to restart Rails before an example is run?

Is it possible to tell rspec to restart Rails before an example is run? I'm building an Engine that hooks into the Rails initialization process and the users can make some configuration changes, in an initializer, that impact how Rails and the Engine are configured. I want to be able to simulate those configuration changes, restart rails and test the result.
I haven't done this feat yet, but as best practice I think your engine tests should be part of the engine and should have minimal dependencies.
Some approaches I've seen and believe you should try and combine:
Mock a minimal parent rails app to test your engine.
Write multiple dummy apps to test with.
Instead of loading the entire rails application, you can split spec_helper and rails_helper in smaller parts, also gaining in setup time.
You can write custom rake tasks to switch environment before spawning a new test thread.
You can also overwrite at runtime the configuration values which reflect in your test (plus: use dependency injection!).
If your initializer is complex enough, you could extract it in a testable helper and wire it up in your test initializers.
Also, there seems to be a gem for that: Combustion.

Integration tests vs Unit tests

I know this has been asked a lot of times, but this example one test confuses me. The test example here:
Testing Routes In ASP.NET MVC
Is this a unit or integration test? On the page it specifies it is a unit test but as I understand it, an integration test are tests that uses real dependencies. So is using the GlobalApplication.RegisterRoutes considered a dependency? So is this an integration test? I'm a bit confused to the extent of what a dependency is.
This is a unit test of a particular functionality of your application: the routes that you have defined.
So is using the GlobalApplication.RegisterRoutes considered a
dependency?
No, that's the subject under test - it's what you are testing. A dependency would be something that this subject depends on in order to work. It is this dependency that can be either mocked (in a unit test) or just using the actual object (in an integration test). For example if your routes were dependent on some database lookup operation then, if you don't mock this db call, you would be writing an integration test.

Are ASP.NET MVC route tests considered Unit Tests or Integration Tests?

So i'm going to add some tests to my project to test my ASP.NET MVC routes. Are they a unit test or an integration test?
I feel like they are a unit test, where integration tests are against db's, 3rd party services (eg. twitter, file upload, etc) .. something I would normally mock out in a unit test.
The reason I'm asking is that I was looking at Ayende's Raccon Blog and noticed they have their route tests listed as Integration Tests.
I would consider them to be unit tests. Your just testing that an endpoint reaches a particular controller action. I think that's a pretty isolated set of functionality.

Resources