fixtures

Unit testing: Is it a good practice to have assertions in setup methods?

寵の児 提交于 2019-12-03 06:36:27
问题 In unit testing, the setup method is used to create the objects needed for testing. In those setup methods, I like using assertions: I know what values I want to see in those objects, and I like to document that knowledge via an assertion. In a recent post on unit tests calling other unit tests here on stackoverflow, the general feeling seems to be that unit tests should not call other tests: The answer to that question seems to be that you should refactor your setup, so that test cases do

factory_girl + rspec doesn't seem to roll back changes after each example

旧街凉风 提交于 2019-12-03 04:57:12
Similar to the problem described here: http://rpheath.com/posts/411-how-to-use-factory-girl-with-rspec in Short (shorten'd code): spec_helper: config.use_transactional_fixtures = true config.use_instantiated_fixtures = false factories.rb: Factory.define :state do f.name "NY" end in my spec before(:each) do @static_model = Factory(:state) # with validate uniqueness of state name end error: duplicate entry name "NY" etc. Question: Shouldn't rspec clear database before each spec example and hence not throwing duplicate entry errors? Things i think off: do you use rake spec to run your testsuite:

Load and use fixture in rails console

大憨熊 提交于 2019-12-03 03:32:39
问题 I wonder if there's a way to load and/or use fixture in rails console. Actually, I'd like to create a user from my fixture users.yml to do some testing without having to go through all the "pain" of doing User.new(:name = "John", :email = "..") each time. I am currently in test environment ( rails c RAILS_ENV=test ). If it's not a good way to do things, please say it. I'm new to Rails so I'm here to learn :) 回答1: You should be able to load your fixtures prior to entering console. Like this:

Is seeding data with fixtures dangerous in Ruby on Rails

拟墨画扇 提交于 2019-12-03 03:27:23
I have fixtures with initial data that needs to reside in my database (countries, regions, carriers, etc.). I have a task rake db:seed that will seed a database. namespace :db do desc "Load seed fixtures (from db/fixtures) into the current environment's database." task :seed => :environment do require 'active_record/fixtures' Dir.glob(RAILS_ROOT + '/db/fixtures/yamls/*.yml').each do |file| Fixtures.create_fixtures('db/fixtures/yamls', File.basename(file, '.*')) end end end I am a bit worried because this task wipes my database clean and loads the initial data. The fact that this is even

Fixtures in Play! 2 for Scala

走远了吗. 提交于 2019-12-03 03:25:27
I am trying to do some integration testing in a Play! 2 for Scala application. For this, I need to load some fixtures to have the DB in a known state before each test. At the moment, I am just invoking a method that executes a bunch of Squeryl statements to load data. But declaring the fixtures declaratively, either with a Scala DSL or in a language like JSON or YAML is more readable and easy to mantain. In this example of a Java application I see that fixtures are loaded from a YAML file, but the equivalent Scala app resorts to manula loading, as I am doing right now. I have also found this

How can I use a parametrized dependent fixture twice in pytest?

笑着哭i 提交于 2019-12-03 03:12:09
I'm trying to use a parametrized fixture multiple times in a single test, with the intent of getting a cartesian product of all of its values. https://stackoverflow.com/a/39444098/102441 shows how to do this for a simple fixture: import pytest @pytest.fixture(params=[0, 1, 2]) def first(request): return request.param second = first # runs 3x3 = 9 times def test_double_fixture(first, second): assert False, '{} {}'.format(first, second) However, this approach falls apart if the parametrization comes from a dependent fixture: import pytest @pytest.fixture(params=[0, 1, 2]) def integer(request):

Doctrine 2. orm:schema-tool:update . Set start id

牧云@^-^@ 提交于 2019-12-03 03:02:13
When I use ./bin/doctrine orm:fixtures:load to populate tables with sample data first migration sets auto incremental table id like 1,2,3,4,5 etc... After second orm:fixtures:load migration command it purges all data and sets ids like 5,6,7,8,9 and so on... How can I reset AI id counter to 1 when I load fixtures many times? $ app/console help doctrine:fixtures:load By default Doctrine Data Fixtures uses DELETE statements to drop the existing rows from the database. If you want to use a TRUNCATE statement instead you can use the --purge-with-truncate flag: ./app/console doctrine:fixtures:load -

Unit testing: Is it a good practice to have assertions in setup methods?

拈花ヽ惹草 提交于 2019-12-02 20:13:56
In unit testing, the setup method is used to create the objects needed for testing. In those setup methods, I like using assertions: I know what values I want to see in those objects, and I like to document that knowledge via an assertion. In a recent post on unit tests calling other unit tests here on stackoverflow, the general feeling seems to be that unit tests should not call other tests: The answer to that question seems to be that you should refactor your setup, so that test cases do not depend on each other. But there isn't much difference in a "setup-with-asserts" and a unit test

Python - Use pytest to test test methods written in subclass

白昼怎懂夜的黑 提交于 2019-12-02 16:58:41
问题 I am a novice to pytest. I have a scenario wherein i wanted to test some test methods written in a subclass. Assume that the following is my code structure class Superclass: def __init__(self, a): self.a = a def dummy_print(): print("This is a dummy function") class TestSubClass(Superclass): def test_1_eq_1(): assert 1 == 1 Upon executing the following command py.test -s -v test_filename.py I get the following error messgae: cannot collect test class 'Test_Super' because it has a init

Python - Use pytest to test test methods written in subclass

丶灬走出姿态 提交于 2019-12-02 09:57:25
I am a novice to pytest. I have a scenario wherein i wanted to test some test methods written in a subclass. Assume that the following is my code structure class Superclass: def __init__(self, a): self.a = a def dummy_print(): print("This is a dummy function") class TestSubClass(Superclass): def test_1_eq_1(): assert 1 == 1 Upon executing the following command py.test -s -v test_filename.py I get the following error messgae: cannot collect test class 'Test_Super' because it has a init constructor The same is mentioned in the pytest documentation as well. Is there a workaround for this? I need