Help with testing #1153
-
I'm migrating to good_job from sidekiq (and switching to solid_cache, bye redis!). With sidekiq, I liked to test the number of jobs, then execute the jobs and test the results. It would look something like this:
So I have two questions:
Thanks so much! Update: I found |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Now that you're using ActiveJob, I would recommend that you do unit testing directly with Active Job's test adapter (which sidesteps GoodJob): https://edgeguides.rubyonrails.org/testing.html#testing-jobs-in-context For integration testing, you can use GoodJob with ActiveJob::Base.queue_adapter = GoodJob::Adapter.new(execution_mode: :external)
MyJob.perform_later
assert_equal 1, GoodJob::Job.where(job_class: "MyJob").count # this is an Active Record model / scope chain
GoodJob.perform_inline
assert_results |
Beta Was this translation helpful? Give feedback.
Now that you're using ActiveJob, I would recommend that you do unit testing directly with Active Job's test adapter (which sidesteps GoodJob): https://edgeguides.rubyonrails.org/testing.html#testing-jobs-in-context
For integration testing, you can use GoodJob with
:external
execution mode, which will cause all jobs to go to the database. Something like: