c# - Structuring TextFixtures in nUnit -


upon unit testing of class, there need test same methods different combination of data in class. can achieved writing several textfixtures , repeating same test methods each one, below.

 [textfixture]  public class whenbuildinglongfoo  {      private foo foo;       [setup]      public void creating()      {           foo = new foo(){height = new fooheight(200)};      }       [test]      public void returnsvalidheight()      {      assert.areequal(200, foo.height);      }   }    [textfixture]   public class whenbuildingshortfoo   {   private foo foo;   [setup]   public void creating()   {        foo = new foo(){height=newfooheight(2);    }    [test]    public void returnsvalidheight()    {         assert.areequal(2, foo.height);     } } 
  1. what best way structure such fixtures, method returnsvalidheight written once?

i came creating public static class utilities in common namespace, has method; please advise better?

something create abstract class such method , derive fixtures it?

  1. how reuse setup among fixtures, varying values?

use testcase attribute run same test different input values. that'll reduce lot of duplicate code. setup method isn't necessary in case either.

[textfixture] public class footests {     [test]     [testcase(200)]     [testcase(2)]     public void returnsvalidheight(int expectedheight)     {         var foo = new foo { height = new fooheight(expectedheight) };          assert.areequal(expectedheight, foo.height);     } } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -