Questions tagged [fixtures]

Fixtures are scopes used for running tests which isolate each test from global namespace pollution and side-effects from previous tests in order to avoid false positives and false negatives

1601 questions
38
votes
5 answers

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

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…
avandeursen
  • 8,458
  • 3
  • 41
  • 51
37
votes
2 answers

Factory Girl + Mongoid embedded documents in fixtures

Let’s say you have the following mongoid documents: class User include Mongoid::Document embeds_one :name end class UserName include Mongoid::Document field :first field :last_initial embedded_in :user end How do you…
GTDev
  • 5,488
  • 9
  • 49
  • 84
37
votes
4 answers

When to use pytest fixtures?

I'm new to testing and I've stumbled across pytest fixtures, but I'm not entirely sure when to use them and why they're useful. For example, see the below code: import pytest @pytest.fixture def input_value(): input = 39 return input def…
the man
  • 1,131
  • 1
  • 8
  • 19
37
votes
4 answers

In Django, getting a "Error: Unable to serialize database" when trying to dump data?

I'm getting an error when I'm trying to dump data to a JSON fixture in Djanog 1.2.1 on my live server. On the live server it's running MySQL Server version 5.0.77 and I imported a lot of data to my tables using the phpMyAdmin interface. The website…
littlejim84
  • 9,071
  • 15
  • 54
  • 77
36
votes
2 answers

Override a pytest parameterized functions name

My parameters determine the name of my parameterized pytest. I will be using a some randomized params for these tests. In order for my reporting names in junit to not get messed up, I'd like to create a static name for each parameterized test. Is it…
SomeGuyOnAComputer
  • 5,414
  • 6
  • 40
  • 72
35
votes
3 answers

Fixtures in RSpec

I'm new to using RSpec for writing tests in a Rails application which uses a MySQL database. I have defined my fixtures and am loading them in my spec as follows: before(:all) do fixtures :student end Does this declaration save the data defined…
Kris
  • 1,403
  • 3
  • 17
  • 26
34
votes
6 answers

Pytest use same fixture twice in one function

For my web server, I have a login fixture that create a user and returns the headers needed to send requests. For a certain test, I need two users. How can I use the same fixture twice in one function? from test.fixtures import login class…
danijar
  • 32,406
  • 45
  • 166
  • 297
33
votes
2 answers

Rails fixtures -- how do you set foreign keys?

I'm reading about Rails fixtures in this guide (thanks, trevorturk). It appears you define classes in a Yaml file and they're automatically loaded into the test DB -- cool. But if you want to specify that this recipe belongs to that cookbook (or…
Ethan
  • 57,819
  • 63
  • 187
  • 237
33
votes
4 answers

How to create fixtures (for a Devise user) as a yml.erb in rails (4.1.5)?

Update 3: It seems like this is specific to fixtures in a .yml.erb - even if I have no templated code, it seems like fixtures in a yml.erb file doesn't get loaded. Having a plain .yml file works. This likely has nothing to do with devise per…
Anand
  • 3,690
  • 4
  • 33
  • 64
32
votes
7 answers

Generate Symfony2 fixtures from DB?

Is it possible to generate fixtures from an existing DB in Symfony2/Doctrine? How could I do that? Example: I have defined 15 entities and my symfony2 application is working. Now some people are able to browse to the application and by using it it…
Stuck
  • 11,225
  • 11
  • 59
  • 104
32
votes
4 answers

pytest fixtures in a separate directory

I'm looking to create a pytest structure where I can separate the fixtures from the tests completely. The reason for this separation is that I want to include the fixtures directory as an external item in subversion and share it between multiple…
Jakob Pogulis
  • 1,150
  • 2
  • 9
  • 19
28
votes
11 answers

Symfony 3.4.0 Could not find any fixture services to load

I am using Symfony 3.4.0, I try to load fixtures with: php bin/console doctrine:fixtures:load An error occurred while creating the data, what's wrong?
Alexander
  • 311
  • 1
  • 3
  • 6
28
votes
3 answers

Rails Fixtures not loading with rspec

So, I'm trying to learn the rspec BDD testing framework in the context of a rails project. The problem I'm having is that I can't, for the life of me, get my fixtures to load properly in rspec descriptions. Disclaimer: Yes, there are better things…
Fishtoaster
  • 1,809
  • 2
  • 20
  • 36
27
votes
2 answers

Rails fixtures vs seeds

I'm learning Ruby on Rails, and I'd like to just make sure I understand the difference between fixtures and seed data. What I understand is that fixtures are basically test data that you run your testing assertions against, and have no persistence…
user2258651
  • 383
  • 5
  • 8
26
votes
4 answers

Functional testing with Rails and Devise. What to put in my fixtures?

Hi I'm wanting to do some functional testing of my Rails 3 app that uses Devise and CanCan. In my User model I have the users age, I want to test that a user can only visit a certain page if they are: Logged in Over 35 I have seen in the Devise…
Jez Caudle
  • 331
  • 1
  • 3
  • 6