ThoughtWorks
  • Contact
  • Español
  • Português
  • Deutsch
  • 中文
Go to overview
  • Engineering Culture, Delivery Mindset

    Embrace a modern approach to software development and deliver value faster

    Intelligence-Driven Decision Making

    Leverage your data assets to unlock new sources of value

  • Frictionless Operating Model

    Improve your organization's ability to respond to change

    Platform Strategy

    Create adaptable technology platforms that move with your business strategy

  • Experience Design and Product Capability

    Rapidly design, deliver and evolve exceptional products and experiences

    Partnerships

    Leveraging our network of trusted partners to amplify the outcomes we deliver for our clients

Go to overview
  • Automotive
  • Cleantech, Energy and Utilities
  • Financial Services and Insurance
  • Healthcare
  • Media and Publishing
  • Not-for-profit
  • Public Sector
  • Retail and E-commerce
  • Travel and Transport
Go to overview

Featured

  • Technology

    An in-depth exploration of enterprise technology and engineering excellence

  • Business

    Keep up to date with the latest business and industry insights for digital leaders

  • Culture

    The place for career-building content and tips, and our view on social justice and inclusivity

Digital Publications and Tools

  • Technology Radar

    An opinionated guide to technology frontiers

  • Perspectives

    A publication for digital leaders

  • Digital Fluency Model

    A model for prioritizing the digital capabilities needed to navigate uncertainty

  • Decoder

    The business execs' A-Z guide to technology

All Insights

  • Articles

    Expert insights to help your business grow

  • Blogs

    Personal perspectives from ThoughtWorkers around the globe

  • Books

    Explore our extensive library

  • Podcasts

    Captivating conversations on the latest in business and tech

Go to overview
  • Application process

    What to expect as you interview with us

  • Grads and career changers

    Start your tech career on the right foot

  • Search jobs

    Find open positions in your region

  • Stay connected

    Sign up for our monthly newsletter

Go to overview
  • Conferences and Events
  • Diversity and Inclusion
  • News
  • Open Source
  • Our Leaders
  • Social Change
  • Español
  • Português
  • Deutsch
  • 中文
ThoughtWorksMenu
  • Close   ✕
  • What we do
  • Who we work with
  • Insights
  • Careers
  • About
  • Contact
  • Back
  • Close   ✕
  • Go to overview
  • Engineering Culture, Delivery Mindset

    Embrace a modern approach to software development and deliver value faster

  • Experience Design and Product Capability

    Rapidly design, deliver and evolve exceptional products and experiences

  • Frictionless Operating Model

    Improve your organization's ability to respond to change

  • Intelligence-Driven Decision Making

    Leverage your data assets to unlock new sources of value

  • Partnerships

    Leveraging our network of trusted partners to amplify the outcomes we deliver for our clients

  • Platform Strategy

    Create adaptable technology platforms that move with your business strategy

  • Back
  • Close   ✕
  • Go to overview
  • Automotive
  • Cleantech, Energy and Utilities
  • Financial Services and Insurance
  • Healthcare
  • Media and Publishing
  • Not-for-profit
  • Public Sector
  • Retail and E-commerce
  • Travel and Transport
  • Back
  • Close   ✕
  • Go to overview
  • Featured

  • Technology

    An in-depth exploration of enterprise technology and engineering excellence

  • Business

    Keep up to date with the latest business and industry insights for digital leaders

  • Culture

    The place for career-building content and tips, and our view on social justice and inclusivity

  • Digital Publications and Tools

  • Technology Radar

    An opinionated guide to technology frontiers

  • Perspectives

    A publication for digital leaders

  • Digital Fluency Model

    A model for prioritizing the digital capabilities needed to navigate uncertainty

  • Decoder

    The business execs' A-Z guide to technology

  • All Insights

  • Articles

    Expert insights to help your business grow

  • Blogs

    Personal perspectives from ThoughtWorkers around the globe

  • Books

    Explore our extensive library

  • Podcasts

    Captivating conversations on the latest in business and tech

  • Back
  • Close   ✕
  • Go to overview
  • Application process

    What to expect as you interview with us

  • Grads and career changers

    Start your tech career on the right foot

  • Search jobs

    Find open positions in your region

  • Stay connected

    Sign up for our monthly newsletter

  • Back
  • Close   ✕
  • Go to overview
  • Conferences and Events
  • Diversity and Inclusion
  • News
  • Open Source
  • Our Leaders
  • Social Change
Blogs
Select a topic
View all topicsClose
Technology 
Agile Project Management Cloud Continuous Delivery  Data Science & Engineering Defending the Free Internet Evolutionary Architecture Experience Design IoT Languages, Tools & Frameworks Legacy Modernization Machine Learning & Artificial Intelligence Microservices Platforms Security Software Testing Technology Strategy 
Business 
Financial Services Global Health Innovation Retail  Transformation 
Careers 
Career Hacks Diversity & Inclusion Social Change 
Blogs

Topics

Choose a topic
  • Technology
    Technology
  • Technology Overview
  • Agile Project Management
  • Cloud
  • Continuous Delivery
  • Data Science & Engineering
  • Defending the Free Internet
  • Evolutionary Architecture
  • Experience Design
  • IoT
  • Languages, Tools & Frameworks
  • Legacy Modernization
  • Machine Learning & Artificial Intelligence
  • Microservices
  • Platforms
  • Security
  • Software Testing
  • Technology Strategy
  • Business
    Business
  • Business Overview
  • Financial Services
  • Global Health
  • Innovation
  • Retail
  • Transformation
  • Careers
    Careers
  • Careers Overview
  • Career Hacks
  • Diversity & Inclusion
  • Social Change
Software TestingTechnology

Twist execution hooks and customizable HTML reports - Part 1

ThoughtWorks ThoughtWorks

Published: Apr 30, 2013

This blog post talks about measuring the execution time for each step and reporting it in Twist HTML reports. This is very helpful to analyze application performance and it also makes it easy to spot parts of the application that aren't performing well. This is the first part of a two-part blog series. The second part talks about consuming this data and drawing a little graph in the HTML report.

Twist provides two types of execution hooks. A global and a fixture level hook. In this blog post, we will be using a global hook to measure the execution time for each step in the scenario. We use the Twist data store to keep the measurements. Twist by default renders data store contents as HTML reports. Let us assume we have a scenario like the following:

We use the hooks defined in "ScenarioExecutionHooks" class.

public class ScenarioExecutionHooks {
    @Autowired
    private TwistScenarioDataStore scenarioStore;
    private long startTime;
    @BeforeEachStep
    public void beforeEachStep() throws Exception {
        startTime = System.nanoTime();
    }
    @AfterEachStep
    public void afterEachStep() throws Exception {
        double elapsedTimeInSec = (double)(System.nanoTime() - startTime) / 1000000000.0;
        IScenarioInformation scenarioInformation = ScenarioInformationFactory.getScenarioInformation();
        scenarioStore.put(scenarioInformation.getCurrentStep().getText(), elapsedTimeInSec);
    }
}

"beforeEachStep" method records the execution start time and "afterEachStep" method records the elapsed time. Finally we add the details into scenario store. Twist will put the scenario store into the HTML report. Below is a preview of the HTML report:

Identifying performance regressions

Measuring the elapsed time can also be used to detect performance regressions. If performance regressions are detected, you can fail the scenario if required. To do that, we will tag the scenario with a tag named "should_execute_within_10_secs" (tags are customizable, "should_execute_within_10_secs" is a just an example). In the "after" hook, we will check the elapsed time and fail if necessary. "should_execute_within_10_secs" tag can be used to detect the scenarios where this check is required.

@AfterEachStep
public void afterEachStep() throws Exception {
    double elapsedTimeInSec = (double)(System.nanoTime() - startTime) / 1000000000.0;
    IScenarioInformation scenarioInformation = ScenarioInformationFactory.getScenarioInformation();
    scenarioStore.put(scenarioInformation.getCurrentStep().getText(), elapsedTimeInSec);
    
    String[] tags = scenarioInformation.getTags();
    for (String tag : tags) {
        if ("should_execute_within_10_secs".equals(tag)
                && elapsedTimeInSec > 10.0) {
            fail("Expected to execute within 10 seconds. But took "
                    + elapsedTimeInSec + " seconds");
        }
    }
}

The report will look like,

Check out our next post, where we explain how to consume this data and plot a little graph on the report.

 

See what's new in Twist 13.1 on our community site or Try Twist now.

 

 

  • What we do
  • Who we work with
  • Insights
  • Careers
  • About
  • Contact

WeChat

×
QR code to ThoughtWorks China WeChat subscription account

Media and analyst relations | Privacy policy | Modern Slavery statement ThoughtWorks| Accessibility | © 2021 ThoughtWorks, Inc.