1. Why write Tests
Rails makes it easy for us to write tests. When we created model and controller, rails helped us create the skeleton code for the test.
By simply running your test code, you can make sure that your code still satisfies the requirements after refactoring.
The r
Replace fixtures with Factory-girl to create mock data
Fixtures
As we described earlier, the rails test system uses fixtures to create mock data, which are written in YAML format and placed in Db/fixtures folders, each with a corresponding file, test/fixtures/ Users.yml.
The data in these fixtures are loaded into the test
The previous blog introduced some knowledge about rails testing. Test the location of the files, the types of tests, test common commands, and some of the resources available, and how to generate mock data using fixtures.
Today we're going to actually write unit tests, and the knowledge we use is mainly fixtures and test
Opening
Today we're going to familiarize ourselves with rails ' integration testing integration test.
Brief introduction
Integration testing is primarily about testing the interactions between multiple controller, and testing the more important workflows in the application to verify that these workflows are in line with the expected assumptions.
Unlike unit tests and functional tests, they are automatic
Unit Test
Unit test for model, mainly in the test model business rules, test model validation validates rules.
Unit test files are stored in the Test/unit folder, and the unit test fi
Functional Testing Functional Test
In rails, the test for each action in a single controller is called a functional test. Controller the request to process the Web, render the requested response to the view.
Content included in functional testing
Did the Web request succeed?
Is the user booted into the correct page
As we've mentioned before, the rails functional test is for controller, testing whether the controller action is performing correctly.
The main contents of the test are:
The test request is correct.
Test whether the user jumps to the correct page.
Replace fixtures with Factory-girl to create analog data 2
In the previous article we introduced Factory-girl, which is a good tool that can be used to replace fixtures in rails to generate mock data.
It is intuitive, easy to read, easy to read and easy to maintain. The most important point is that it is oriented to model, business-oriented, application-oriented, and fixtures analog data is database-oriented. But our unit tests, functional tests, an
Brief introduction
Each rails application includes three environments:
Production environment
Development environment
Test environment
Our test is run in the test environment, and if the test involves a database, it will operate in the
Rake is a program written in Ruby and we use rake to read the rakefile. And Rakefile contains defined tasks, each with a name, and some of the tasks it relies on, and a set of actions to perform. Now let's take a look at the rake in Rails. When you create a project using rails ' generate scripts, you automatically generate a Rakefile file in the root directory of your project to help you accomplish a lot of
We've already completed a simple shopping cart, and from this start we'll see how to test in rails.
When we created the shopping cart program in our depot directory, there is already a test directory, which is for us to test preparation. So far, we've seen that the fixtrues and Functional,unit directories inside have
The essay briefly understands the use of rails ' test and test data, and this time to see how to add a test to a model for deletion and modification.
1. Or using the last written products_test.rb, modify the Test_turth method by the name Test_create and make the contents:
def test_create
assert_kind_of Product, @pro
The unit test of JS is a big problem. The authors believe that Ruby's testing tools are more flexible than JS's test tools.Most JS code is ultimately about responding to user behavior and changing elements in the DOMThere are no javascript points of knowledge. The first two sections have several new test tools, and a lot of configuration, temporary pass.
In the practice of agile development, the test drive is indispensable. This article looks at a test-driven development example in rails.
Before we wrote and conducted some unit tests and functional tests, our customers suddenly asked to add a feature: Each user of the system could query the product.
We first sketched some sketches to sort out our ideas and desi
The previous essay introduces rails ' conventions on functional testing. This time we'll go on to the controller test.
Before we test is login, you can meet, users in login will start shopping after the action, so we now to test Store_controller, we first test the index met
The last Test Modeul problem has not been resolved, but the following to continue, this time to test controller.
1. In the test\functional directory, rails has generated a corresponding test file for our controller, and note that Application_controller does not generate
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.