Good readable test names in C #

I read in FsUnit the following valid method / class name 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 a method or cool names like this in C #?

+3
source share
4 answers

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

[TestMethod]
public void When_Asked_Whether_It_Is_On_It_Answers_True() {}
+6
source

do as the book says:

public void MethodNameUnderTest_CaseExplained_ExpectedResult()

very readable

+1
source

.

,

[Test]
public void SomeMethodShouldCallServiceManagerWithTheCorrectParameters()

, . , , . , , .

+1

In fact, there is a terrible Unicode hack that you can do if you really want to have spaces in your tests.

Jimmy Bogard explains:

http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/02/16/spaces-in-identifier-names-in-c.aspx

Basically, use the UTF-16 0x200E character as a space, breaking the keyboard with AutoHotkey so you can easily enter that character when you need to.

Now the question is, do you want to do this?

0
source

Source: https://habr.com/ru/post/1761468/


All Articles