Is it possible to parameterise the NUnit test case display name when using ``Ticked method names``?

f#, nunit

Solution

This might not be exactly what you need, but if you want to go beyond unit testing, then TickSpec (a BDD framework using F#) has a nice feature where it lets you write parameterized scenarios based on back-tick methods that contain regular expressions as place holders.

For example, in Phil Trelford's blog post, he uses this to define tic-tac-toe scenario:

Scenario: Winning positions
    Given a board layout:
        | 1 | 2 | 3 |
        | O | O | X |
        | O |   |   |
        | X |   | X |
    When a player marks X at <row> <col>
    Then X wins

Examples:
    | row    | col    | 
    | middle | right  |
    | middle | middle |
    | bottom | middle |

The method that implements the `When` clause of the scenario is defined in F# using something like this:

let [<When>] ``a player marks (X|O) at (top|middle|bottom) (left|middle|right)`` 
        (mark:string,row:Row,col:Col) =       
    let y = int row             
    let x = int col        
    Debug.Assert(System.String.IsNullOrEmpty(layout.[y].[x]))
    layout.[y].[x] <- mark  

This is a neat thing, but it might be an overkill if you just want to write a simple parameterized unit test - BDD is useful if you want to produce human readable specifications of different scenarios (and there are actually other people reading them!)

Problem

I am testing out F# and using NUnit as my test library; I have discovered the use of double-back ticks to allow arbitrary method naming to make my method names even more human readable. I was wondering, whether rightly or wrongly, if it is possible to parameterise the method names when using NUnit's `TestCaseAttribute` to change the method name, for example: ``` [<TestCase("1", 1)>] [<TestCase("2", 2)>] let ``Should return #expected when "#input" is supplied`` input expected = ... ```

Original source