Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good readable testnames in c#

I read in FsUnit that the following are valid method/classnames in F#:

[<TestFixture>] 
type ``Given a LightBulb that has had its state set to true`` ()=
   let lightBulb = new LightBulb(true)

   [<Test>] member test.
    ``when I ask whether it is On it answers true.`` ()=
       lightBulb.On |> should be True

Is there a way to have method or classnames like this in c#?

like image 247
Nils Avatar asked Oct 24 '25 02:10

Nils


2 Answers

No, you cannot have spaces or punctuation in a C# method name. You can do:

[TestMethod]
public void When_Asked_Whether_It_Is_On_It_Answers_True() {}
like image 165
driis Avatar answered Oct 25 '25 15:10

driis


My preferred method of naming tests does not include underscores at all.

For example,

[Test]
public void SomeMethodShouldCallServiceManagerWithTheCorrectParameters()

With that said, consistency is key. There is no penalty for having a method name as long as you want it. So if you prefer to separate words with underscores, then go for it.

Ian

like image 35
Ian P Avatar answered Oct 25 '25 16:10

Ian P



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!