Craftsman at Work

I'm Artur Karbone, coding software architect and independent IT consultant and this is my blog about craftsmanship, architecture, distributed systems, management and much more.

Read Your Functional Tests as a Book in C# Part 3 : High Level of Abstraction

The Goal

In this series of posts I'm going to show how to leverage clean code principles when writing functional tests.

The Code. At last

Here is the code, describing a single use-case. Reading it should take, perhaps, a minute.
Each line literally represents one step from the testing scenario and reveals the intention. It looks so high-level and clean. Moreover it is on the same layer of abstraction. If You as a reader want more details, it's fine. Just press F12 in Your Visual Studio and go to the definition:

  [TestFixture]
    public class BookForwarderScenario : BaseIntegrationTest
    {
        [Test]
        [ImpersonateRandomSystemPortalUser]
        public void BookSingleForwarderFlow()
        {            
           CustomerApp
                .NavigateToRegisterAndBook()
                .CreateBookForwarderContext()
                .ChooseFirstOrder()
                .LaunchBookingWizard()
                .SelectFirstForwarder()
                .GoToTheNextWizardStep()
                .SelectFirstContact()
                .GoToTheNextWizardStep()
                .SkipAgreedFreight()
                .Book()
                .EnsureNotification()
                .EnsureOrderHasGoneFromGrid()
                .GoToFollowUp()
                .EnsureBookedOrderExists();              
        }
    }

Let me explain the scenario by providing some visual information, a piece of description and specific code excerpt from the block above.

  • User goes to the "Register and Book" menu, where some order is being selected and booking process is being launched (Clicking "Book Forwarder" button).

The code describing this particular piece of flow:

    .NavigateToRegisterAndBook()
    .CreateBookForwarderContext()
    .ChooseFirstOrder()
    .LaunchBookingWizard()
  • On the first screen of the wizard user selects a forwarder in which he is interested in:

The code describing this particular piece of flow:

    .SelectFirstForwarder()
    .GoToTheNextWizardStep()
  • On the second screen of the wizard user selects a contact person in which he is interested in:

The code describing this particular piece of flow:

    .SelectFirstContact()
    .GoToTheNextWizardStep()
  • At the third step user can enter some specifications like fuel charge, freight charge, etc. (User can skip this step for now) The code describing this particular piece of flow:
    .SkipAgreedFreight()               
  • Fourth step is kind of a summary, where user can double check entered data, go back and edit it or book the forwarder.

The code describing this particular piece of flow:

    .Book()               
  • A green notification is being showed if operation is successful

The code describing this particular piece of flow:

    .EnsureNotification()
  • Booked order leaves the "Register and Book" grid and goes to the "Follow Up" page.

The code describing this particular piece of flow:

  .EnsureOrderHasGoneFromGrid()
  .GoToFollowUp()
  .EnsureBookedOrderExists(); 

Posts in this series:

Part 1: The Tradegy

Part 2: Setting Up The Stage

Part 3: High Level of Abstraction

Part 4: A Context for Your Scenario

Part 5: Leverage Fluent Interface

comments powered by Disqus