2

So I'm starting to learn how to write unit tests, and I'm starting with Rails (I've fixed a few Rspec tests to start, but now I'm writing Javascript ones).

I understand at least the basics of an MVC framework, and I understand Models (In rails at least). I still need to learn more though of course.

However, when running unit tests (I'm using teaspoon-jasmine right now)...what exactly is happening?

Lets say I'm testing a Function in X controller, is that controller being called by itself? Or is the app and all controllers being initiated? Or what? What about if the function interacts with the DOM....how does that work? I know you can use fixtures but what would it normally do? Does a view or something get called by itself with no data?

The whole process is just a bit confusing, I understand integration tests because the server literally gets fired up and steps through each component, but I'm not sure how unit tests actually run.

2 Answers 2

2

Unit tests can exist in both server-side rails/ruby code and also in client side javascript unit tests.

The unit tests on the server side usually focus on the models. In Ruby these are the rspec or test unit tests and are written in Ruby.

The unit tests on the client side are frequently written in Jasmine. Sometimes Konacha. They will often stub out the HTML (this is why, when they do that, they are Unit and not Integrated or User Acceptance tests).

Controller tests that mock and stub out models are unit tests, but controller tests that don't may be considered integration tests.

At the end of the day unit tests are just bits of code that sit by the app code and exercise it. Their dependencies (aside from the specific app code under test) should be stubbed out.

2

Unit tests have nothing in common with MVC. You run your unit test independently of Rails.

Unit test execute your code for models etc, but you don't call them from web framework which is there to serve web pages.

It seems to me that you need to improve your general programming skills too. Persevere, and it all the puzzle will fit, eventually.

1
  • Yup, Javascript in general is my weak point and I never really worked with a Web framework like rails...so a lot of it is quite confusing ha.
    – Mercfh
    Commented Mar 21, 2017 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.