Skip to content

Failing unit tests #668

Closed
Closed
@bart-degreed

Description

@bart-degreed

Description

When I run dotnet test on my machine with the docker image, I get about 167 errors. Today I investigated what is going on and traced down the cause of this. For reasons unknown to me, the tests in NoEntityFrameworkTests execute prior to most other tests that use entity framework.

NoEntityFrameworkTests creates a table named TodoItems in PostgreSQL with 9 columns, based on class NoEntityFrameworkExample.Models.TodoItem. This causes test Can_Create_TodoItems to fail with message:

{"errors":[{"title":"PostgresException","detail":"23502: null value in column \"CreatedDate\" violates not-null constraint","status":"500"}]}

which makes sense because the column is non-nullable, the test specifies no value and NoEntityFrameworkExample.Data.AppDbContext has no OnModelCreating method that specifies a default column value (like JsonApiDotNetCoreExample.Data.AppDbContext does).

I found that deleting the database and manually running a single test that uses JsonApiDotNetCoreExample.Data.AppDbContext (for example: JsonApiDotNetCoreExampleTests.Acceptance.HttpReadOnlyTests.Allows_GET_Requests) fixes all failing tests. It creates the 15 columns from JsonApiDotNetCoreExample.Models.TodoItem in PostgreSQL, which happen to not conflict with the 9 columns needed by NoEntityFrameworkTests. As a side effect, the non-nullable CreatedDate now has a default value in the database, which makes test Can_Create_TodoItems succeed as well.

So to summarize, the issue is caused by two different versions of TodoItem which are stored in the exact same database location, combined with non-deterministic ordering of test execution.

I think the fix may be as simple as moving them into different schemas, combined with passing a CreatedDate value in test Can_Create_TodoItems.

Environment

Latest master branch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions