What do we call testing methods, where do we test several conditions?

I follow the method specified in Roy Osherov’s book “The Art of Testing Unit”, while the name testing methods are MethodName_Scenario_Expectation . It is great for my "single" tests. But for the tests that I write in the controller or coordinator class, there is no need for a method that I want to test.

For these tests, I create several conditions that make up one scenario, and then check the wait. For example, I can set some properties in different instances, generate an event, and then check if my expectation from the controller / coordinator is fulfilled. Now my controller processes events using a private event handler. My scenario here is that I set some properties, say 3

condition1, condition2 and condition 3

Also in my script there is

event raised

I do not have a method name, since my event handler is private. What is the name of this testing method?

+3
source share
4 answers

In this case, I would use several tests and another naming convention:

  • ClassName_Scenario ( )
  • Expectation1, Expectation2, Expectation3...

, [SetUp]

, - :

[TestFixture]
public class ClassName_WhenScenarioX
{
     [SetUp]
     void InitContextForScenarioX()
     {
     }

     [Test]
     void ShouldDoY()
     {
         Assert.That(...)
     }

     [Test]
     void ShouldRaiseEventZ()
     {
         Assert.That(...)
     }
}

, , ( , )

+6

, , . , - . , , , , (1) (2) - , .

:

[TestFixture]
public class ClassNameTests
{
     [SetUp]
     void BeforeEveryTest()
     {
     }

     [Test]
     void ParsesCsvStringsToLists()
     {
         Assert.That(...)
     }

     [Test]
     void ThrowsMyExceptionWhenInputStringIsMalformed()
     {
         Assert.That(...)
     }
}
+1

(, , ), .

, , , , . , . , / . KISS...

I must add that I work with outdated code, and our scripts and unit tests are usually more cumbersome, then there will be a unit test tutorial. In addition, the interfaces we are testing are quite simple, often having one “executable” method style for each class.

+1
source

If condition1, condition2, and condition3 are a business rule, then name it after the rule.

0
source

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


All Articles