ruby on rails

Unit Tests, Functional Tests, Integration Tests

흰두부1 2020. 11. 13. 17:27

Unit Test: Models, individual units of the application (like a validation) are working

 

Functional Tests: Controllers, a function is working, for example is before_action stopping a non-logged in user form performing an action

 

Integration Tests: Full features, start to finish of a business process, example: a user signs up for the app

 

# rails에서의 unit test

project/test

에서 진행하면 된다.

 

나같은 경우는 category model을 테스트 할 것이므로

models/category.rb 파일을 만들고

require 'test_helper'



class CategoryTest < ActiveSupport::TestCase



test "category should be valid" do

@category = Category.new(name: "Sports")

assert @category.valid?

end



end

위와 같이 코드를 작성한다.

 

실행은 console에서 rails test

E

Error:
CategoryTest#test_category_should_be_valid:
ActiveRecord::StatementInvalid: Could not find table 'categories'
    test/models/category_test.rb:6:in `block in <class:CategoryTest>'
E

Error:
CategoryTest#test_category_should_be_valid:
NameError: uninitialized constant CategoryTest::Category
    test/models/category_test.rb:6:in `block in <class:CategoryTest>'

와 같이 log가 출력된다.