Can anyone recommend resources on building unit, integration, and other tests, and what to test, what I should be looking for, etc.?
I spent a lot of time trying to test "the right way" in Rails. There is none.
There is only a right way for you/your product/team/business right now. Do what works, and iterate and refactor when you find you spend too much time testing (that is, above 50%).
Source: I spend a lot of time working with testing at https://circleci.com
In general, you want to write the smallest test that will work. Unit tests are always better (and you dont need to stub anything or mock anything if you're lucky).
Note that your problem might be your software. If you write relatively decouples and composible code, testing it should be easy (and you can go a long time without mocking anything). So if you're using fat models for example, that's very easy to test.
Like the other dude said start with model tests because they are generally the easiest to work with.
Maybe start off with something basic. Write down a list of validation constraints that are necessary for the model you're testing in normal english.
Example, maybe you would do something like this for a Profile model.
"expect error when first name is empty"
"expect error when last name is empty"
"expect error when e-mail address is empty"
"expect error when e-mail address is an invalid format"
To get these working with the built in rails 4 test framework you just need to change them so they read: test "the description would go here" do
# insert test code here
end
I'll fill in 1 test for you and you can do the rest. test "expect error when first name is empty" do
@profile = Profile.new
@profile.first_name = ""
refute @profile.save
end
If you have no validations in your Profile model then this test will fail because it WILL save. So your goal is to make it pass. Now you would write your validation in the model as so: validates :first_name, presence: true
If you re-run the test it should pass now because active record will throw an error saying first name can't be blank. The test is designed to refute (ie. refuse) saving the model, which is the opposite of assert.IMO just read through this: http://guides.rubyonrails.org/testing.html
At Codeship we focus on functional tests first. We use Cucumber/Capybara/Selenium a lot to test the user facing functionality. This way we can be sure that the feature works on the highest level. For some parts you might need to go down to unit tests, but start with functional tests first.
If you want to get started with testing your system try the following:
Everyone in your team writes down his 7 most important workflows in the application from a users perspective and ranks them. Then put all of the workflows together and try to find the 7 most important ones your team agrees on. Then find a tool that helps you test those from a users perspective. Build the whole toolchain (Tetsing tools on every developer machine, Continuous Integration server/service, ...) so adding new tests is trivial.
Now there is no more excuse not to write tests.
For mocking take a look at a screencast we did a while ago:
http://blog.codeship.io/2013/06/11/testing-tuesday-9-stubbin...
But still the most important thing with testing is getting started and having the whole workflow in place. Even if there is just one test, getting to a point where it is easy to add new tests needs to be priority #1