provide a mechanism to log spock-blocks on the fly #645

Open
raghukiranp opened this Issue Sep 15, 2016 · 0 comments

Projects

None yet

1 participant

@raghukiranp
raghukiranp commented Sep 15, 2016 edited

Issue description

Spock should provide a mechanism/option to let users log/report spock block labels on the fly when the test execution is happening.
Having the BDD reports in logs can be a good addition and provides a context of what is happening when we analyze really huge console logs in test runs.

Context for this enhacement

We are working on a huge enterprise application Integration and are leveraging spock to write tests
Our specifications include verifying contents across multiple apps and validate the contents using Spock.

How to reproduce / Show me how it should look?

This is how a simple test case of ours looks like

def 'Test interacting with two different apps and having too much action and loggin in Helpers'() {

    when: 'User Makes some changes in admin Application'
        def res = AdminHelper.createNewProductInCatalog("MyAwesomeProduct"); // Performs a series of actions and logs stuff

    then: 'Response message from admin is as expected'
        res.status == true

    when: 'user Publishes the changes to Production Server'
        def prodResponse = AdminHelper.publishChangesToProduction(); //Perfors a series of actions and logging 

    then: 'production response should have a success message and 0 Status code'
        prodResponse.message == "success"
        prodResponse.statusCode == 0

    when: 'user connects to Production Server and gets the CatalogContent'
        def catalogContent = ProductionHelper.getCatalogContent(); // Peroforms series of actions and logging

    then: 'User validates if the product he created is in the Catalog'
        catalogContent.product[0].name = "MyAwesomeProduct"
}

This is the kind of logging I am trying to Achieve

when: 'User Makes some changes in admin Application'
    GET : http://myAdminServer.company.com/rest/catalog/products
    HTTP/1.1 200 OK
    POST : http://myAdminServer.company.com/rest/catalog/products/MyAwesomeProduct
    HTTP/1.1 200 OK
then: 'Response message from admin is as expected'
    <<ALL VALIDATIONS PASSED>>
    <<Parameter to log the statement / Success message here? >>
when: 'user Publishes the changes to Production Server'
    POST : http://myAdminServer.company.com/rest/publish
    HTTP/1.1 200 OK
then: 'production response should have a success message and 0 Status code'
    <<ALL VALIDATIONS PASSED>>
when: 'user connects to Production Server and gets the CatalogContent'
    GET : http://www.company.com/rest/products
    HTTP/1.1 200 OK
then: 'User validates if the product he created is in the Catalog'
    <<ALL VALIDATIONS PASSED>>

What have I done before raising this issue

I tried creating my own Spock extension with mySpockRunListener registered, I customize logging and reporting and got below log.

  • Below are my Observations
    • There is no beforeBlock and afterBlock contracts defined in AbstractRunListener class, effectively binding us to use beforeFeature and afterFeature methods to do things and access blocks.
    • I tried logging BlockInfo in beforeFeature method and this is how the output is turning out to which is not of much help when analyzing results that log a lot of info.
    • Is it possible to modify SpecParser.java class to treat every Block as a method too in the ObjectModel and provide a beforeBlock and afterBlock contract to end users to have better Reporting logging and Documenting capabilities?
when: 'User Makes some changes in admin Application'
then: 'Response message from admin is as expected'
when: 'user Publishes the changes to Production Server'
then: 'production response should have a success message and 0 Status code'
when: 'user connects to Production Server and gets the CatalogContent'
then: 'User validates if the product he created is in the Catalog'
GET : http://myAdminServer.company.com/rest/catalog/products
HTTP/1.1 200 OK
POST : http://myAdminServer.company.com/rest/catalog/products/MyAwesomeProduct
HTTP/1.1 200 OK
POST : http://myAdminServer.company.com/rest/publish
HTTP/1.1 200 OK
GET : http://www.company.com/rest/products
HTTP/1.1 200 OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment