Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's inconvenient to have different base classes for tests with results and test without results #44

Closed
IharBury opened this issue Nov 15, 2016 · 0 comments

Comments

@IharBury
Copy link
Contributor

Often there are many tests for the same subject sharing most of the givens and having different whens. It's convenient to reuse them as a common base class like:

public abstract class Given_a_computer : GivenSubject<IComputer>
{
  public Given_a_computer()
  {
     Given(() =>
     {
       WithSubject(new Computer());
     }
  }
}

public class When_Windows_is_installed : Given_a_computer
{
  public When_Windows_is_installed()
  {
    When(() => Subject.InstallWindows());
  }

  [Fact]
  public void Then_it_must_die()
  {
    Subject.Should().BeDead();
  }
}

public class When_Linux_is_installed : Given_a_computer
{
  public When_Windows_is_installed()
  {
    When(() => Subject.InstallLinux());
  }

  [Fact]
  public void Then_it_should_work()
  {
    Subject.Should().Work();
  }
}

However, it's not possible to have a common base class for test with results and without results because they must have different Chill base class (GivenSubject<TSubject> vs GivenSubject<TSubject, TResult>, or GivenWhenThen vs GivenWhenThen<TResult>).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants