Is it good practice to have a unit test for a simple data method?

by Bob Horn   Last Updated April 07, 2018 18:05 PM

I have a simple data method that does this:

public void Write(Foo foo)
{
  db.Foos.Add(foo);
  db.SaveChanges();
}

I was asked to write unit tests for this. To do so, I had to create a fake DbContext and DbSet. I'm basically just asserting that Add() was called on the DbSet, and that Save() was called on the DbContext.

My concern is that it's too tightly coupling the test to the code. The test is basically dictating how the code does its job, instead of what it does.

I'm just looking for a sanity check here. Am I wrong? Is it good to have tests like this?



Related Questions





Integration Tests of Entity Framework's Fluent API

Updated February 28, 2018 06:05 AM

Per-Module Unit Testing in ZF2

Updated April 10, 2018 07:05 AM