Listeners and method hooks on 'before' examples

13 views
Skip to first unread message

Nigel Charman

unread,
Oct 29, 2016, 4:34:31 PM10/29/16
to concordion-dev

Since Concordion 2.0, specs can contain an example named 'before' which is executed prior to every other example. We also added example listeners, and @BeforeExample and @AfterExample method hooks.

A couple of questions I'd like some opinions on:

  1. Should example listeners and @BeforeExample and @AfterExample method hooks be triggered for the 'before' example? (currently, example listeners are called but method hooks are not)
  2. If "no" to question 1, should the @BeforeExample method hook for the actual example be called before or after its related 'before' example?
Andrew Sumner is raising pull request 225 "to ensure that extensions get beforeExample events in order extensions registered, and afterExample events in reverse order to which they were registered". This alters the behaviour in this area. so keen to hear some opinions.

Nigel

Tim Wright

unread,
Oct 29, 2016, 8:19:48 PM10/29/16
to Nigel Charman, concordion-dev

My (simplistic) view is that the "before" example in the specification isn't a real example and shouldn't have the listeners triggered. Like how we don't trigger listeners for code annotated @Before in the fixture.

Tim

--
You received this message because you are subscribed to the Google Groups "concordion-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to concordion-dev+unsubscribe@googlegroups.com.
To post to this group, send email to concordion-dev@googlegroups.com.
Visit this group at https://groups.google.com/group/concordion-dev.
To view this discussion on the web, visit https://groups.google.com/d/msgid/concordion-dev/13e7b783-6be6-02ac-a373-135200a37101%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Tim Wright

unread,
Oct 29, 2016, 8:21:04 PM10/29/16
to Nigel Charman, concordion-dev
For part 2, we should (for consistency) use the same logic as @Before annotated methods. This likely means that the @BeforeExample annotated methods will be called after the "before" code is run - because that's what jUnit does (I hope :)

Tim
On 30 October 2016 at 13:19, Tim Wright <t...@tfwright.co.nz> wrote:

My (simplistic) view is that the "before" example in the specification isn't a real example and shouldn't have the listeners triggered. Like how we don't trigger listeners for code annotated @Before in the fixture.

Tim
On 30 October 2016 at 09:34, Nigel Charman <nigel.ch...@gmail.com> wrote:

Since Concordion 2.0, specs can contain an example named 'before' which is executed prior to every other example. We also added example listeners, and @BeforeExample and @AfterExample method hooks.

A couple of questions I'd like some opinions on:

  1. Should example listeners and @BeforeExample and @AfterExample method hooks be triggered for the 'before' example? (currently, example listeners are called but method hooks are not)
  2. If "no" to question 1, should the @BeforeExample method hook for the actual example be called before or after its related 'before' example?
Andrew Sumner is raising pull request 225 "to ensure that extensions get beforeExample events in order extensions registered, and afterExample events in reverse order to which they were registered". This alters the behaviour in this area. so keen to hear some opinions.

Nigel

--
You received this message because you are subscribed to the Google Groups "concordion-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to concordion-dev+unsubscribe@googlegroups.com.
To post to this group, send email to concord...@googlegroups.com.

Nigel Charman

unread,
Oct 29, 2016, 11:40:53 PM10/29/16
to Tim Wright, concordion-dev
Thanks Tim, that's conveniently how the code is working now :) I've updated a couple of specs and made a PR on Andrew's eventOrder branch to reflect this.

If anyone has any concerns, please shout out!

Nigel

andrew...@xtra.co.nz

unread,
Oct 30, 2016, 6:36:37 AM10/30/16
to concordion-dev
My only concern is for the logging extension as this listens for the before/afterExample events and directs the log ouput to the appropriate file. If answer is no then any log output would be directed to the specifications log file rather than to a before example specific log so I guess either way works.

Tim Wright

unread,
Oct 30, 2016, 1:21:37 PM10/30/16
to concordion-dev, andrew...@xtra.co.nz

Interesting. Having never used the log extension, I'd expect the output from the before bits to be included in the log for the example. So we get a full view of what happened when running that example. 

Tim
021 251 5593
Sent from phone.




--
You received this message because you are subscribed to the Google Groups "concordion-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to concordion-de...@googlegroups.com.

To post to this group, send email to concord...@googlegroups.com.
Visit this group at https://groups.google.com/group/concordion-dev.

Nigel Charman

unread,
Oct 30, 2016, 1:47:36 PM10/30/16
to Andrew, concord...@googlegroups.com
Would you check with the 2.1.0-SNAPSHOT please, which has implemented "no" (conditional check for !isBeforeExample around the announceBefore/AfterExample method calls in ExampleCommand#execute())?

If answer were "yes", you would only get "before" as the example name, so I don't know how it would be directed to the right example file anyway? Maybe we'd need additional events in the ExampleListener?

Nigel
--

Tim Wright

unread,
Oct 30, 2016, 2:04:58 PM10/30/16
to Nigel Charman, Andrew, concordion-dev

I am thinking that the example listener trigger should be triggered before the before is called and after the example has finished - so we consider executing the before part to be part of the example. That will make sure the before part of the example goes into the same logs as the example.

The easiest ways to do this (IMHO) are:
* ConcordionRunner.run method
* Hooking into jUnit's listener framework.

 Tim
On 31 October 2016 at 06:47, Nigel Charman <nigel.ch...@gmail.com> wrote:
Would you check with the 2.1.0-SNAPSHOT please, which has implemented "no" (conditional check for !isBeforeExample around the announceBefore/AfterExample method calls in ExampleCommand#execute())?

If answer were "yes", you would only get "before" as the example name, so I don't know how it would be directed to the right example file anyway? Maybe we'd need additional events in the ExampleListener?

Nigel


On 30/10/16 23:36, andrew...@xtra.co.nz wrote:
My only concern is for the logging extension as this listens for the before/afterExample events and directs the log ouput to the appropriate file. If answer is no then any log output would be directed to the specifications log file rather than to a before example specific log so I guess either way works.

On Sunday, October 30, 2016 at 9:34:31 AM UTC+13, Nigel Charman wrote:

Since Concordion 2.0, specs can contain an example named 'before' which is executed prior to every other example. We also added example listeners, and @BeforeExample and @AfterExample method hooks.

A couple of questions I'd like some opinions on:

  1. Should example listeners and @BeforeExample and @AfterExample method hooks be triggered for the 'before' example? (currently, example listeners are called but method hooks are not)
  2. If "no" to question 1, should the @BeforeExample method hook for the actual example be called before or after its related 'before' example?
Andrew Sumner is raising pull request 225 "to ensure that extensions get beforeExample events in order extensions registered, and afterExample events in reverse order to which they were registered". This alters the behaviour in this area. so keen to hear some opinions.

Nigel
--
You received this message because you are subscribed to the Google Groups "concordion-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to concordion-dev+unsubscribe@googlegroups.com.
To post to this group, send email to concordion-dev@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "concordion-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to concordion-dev+unsubscribe@googlegroups.com.
To post to this group, send email to concordion-dev@googlegroups.com.

Tim Wright

unread,
Oct 30, 2016, 2:07:26 PM10/30/16
to Nigel Charman, Andrew, concordion-dev

Actually, I mean ConcordionRunner.invoke. Not .run.

FixtureRunner.run might also be good.

Tim
To post to this group, send email to concord...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "concordion-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to concordion-dev+unsubscribe@googlegroups.com.
To post to this group, send email to concord...@googlegroups.com.

Nigel Charman

unread,
Oct 30, 2016, 2:35:53 PM10/30/16
to Tim Wright, Andrew, concordion-dev
However the example listener events include element and resultRecorder parameters, which aren't available in FixtureRunner.run.

We could announce an additional event from FixtureRunner.run which only included the exampleName.

If we called this new event before/afterProcessingExample, we would have the following events when running the example 'myExample' in a spec which has a 'before' example:
beforeProcessingExample('myExample')
    beforeExample('before', element, resultRecorder)
    afterExample('before', element, resultRecorder)
    beforeExample('myExample', element, resultRecorder)
    afterExample('myExample', element, resultRecorder)
afterProcessingExample('myExample')
Nigel

Tim Wright

unread,
Oct 30, 2016, 2:54:47 PM10/30/16
to Nigel Charman, Andrew, concordion-dev

That seems complex.

Andrew: would it be useful for your extensions?

Tim

Andrew Sumner

unread,
Oct 30, 2016, 5:13:34 PM10/30/16
to Tim Wright, Nigel Charman, concordion-dev

Funnily enough, before I read Nigel's reply my suggestion was going to be: perhaps it could be trigger beforeExample (for example) then execute 'before', then execute example?


So this would work very well for the logging extension:


  beforeProcessingExample('myExample')
    beforeExample('before', element, resultRecorder)
    afterExample('before', element, resultRecorder)
    beforeExample('myExample', element, resultRecorder)
    afterExample('myExample', element, resultRecorder)
  afterProcessingExample('myExample')

I assume if there is no before example then we'd get this:


  beforeProcessingExample('myExample')

    beforeExample('myExample', element, resultRecorder)
    afterExample('myExample', element, resultRecorder)
  afterProcessingExample('myExample')


Like you say it does seem a bit complex and for the minor inconvenience of having to look in the specification log file for 'before' related logs then I'm not to concerned as I've never actually used a 'before' example yet.


Andrew



From: concord...@googlegroups.com <concord...@googlegroups.com> on behalf of Tim Wright <t...@tfwright.co.nz>
Sent: Sunday, 30 October 2016 6:54 p.m.
To: Nigel Charman
Cc: Andrew; concordion-dev
Subject: Re: [concordion-dev] Re: Listeners and method hooks on 'before' examples
 

That seems complex.

Andrew: would it be useful for your extensions?

Tim

--
Tim
021 251 5593
http://www.linkedin.com/in/drtimwright 
View Tim Wright’s professional profile on LinkedIn. LinkedIn is the world's largest business network, helping professionals like Tim Wright discover inside connections to recommended job candidates, industry experts, and business partners.

--
You received this message because you are subscribed to a topic in the Google Groups "concordion-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/concordion-dev/p98v3g3Vz5U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to concordion-de...@googlegroups.com.

To post to this group, send email to concord...@googlegroups.com.
Visit this group at https://groups.google.com/group/concordion-dev.

Nigel Charman

unread,
Nov 6, 2016, 3:18:19 AM11/6/16
to Andrew Sumner, Tim Wright, concordion-dev
Hi Andrew and Tim,

The 2.1.0-SNAPSHOT went out without these changes in.

If we wanted to simplify, and not break the ExampleListener interface, we could just use:


    beforeExample('before', element, resultRecorder)
    afterExample('before', element, resultRecorder)
    beforeExample('myExample', element, resultRecorder)
    afterExample('myExample', element, resultRecorder)

The downside is that it might complicate any extension that wanted to link the 'before' example in with the actual example. As an alternative, the before example name could be changed to say which example it is before, eg:

    beforeExample('before:myExample', element, resultRecorder)
    afterExample('before:myExample', element, resultRecorder)

    beforeExample('myExample', element, resultRecorder)
    afterExample('myExample', element, resultRecorder)

I'll be keen to know which of these would work better for you Andrew?

I'll be releasing a new snapshot in the next couple of days to remove the "concise markdown table format". This change could go in at the same time, or in a future snapshot if you want to try the new snapshot first.

Nigel

On 31/10/16 10:16, Andrew Sumner wrote:

I'm sending this again from a different account.  Outlook seems to have stopped sending emails from my xtra account and just saves them to draft so sorry if you get it twice.


Funnily enough, before I read Nigel's reply my suggestion was going to be: perhaps it could be trigger beforeExample (for example) then execute 'before', then execute example?


So this would work very well for the logging extension:


  beforeProcessingExample('myExample')
    beforeExample('before', element, resultRecorder)
    afterExample('before', element, resultRecorder)
    beforeExample('myExample', element, resultRecorder)
    afterExample('myExample', element, resultRecorder)
  afterProcessingExample('myExample')

I assume if there is no before example then we'd get this:


  beforeProcessingExample('myExample')

    beforeExample('myExample', element, resultRecorder)
    afterExample('myExample', element, resultRecorder)
  afterProcessingExample('myExample')


Like you say Tim, it does seem a bit complex and for the minor inconvenience of having to look in the specification log file for 'before' related logs then I'm not to concerned as I've never actually used a 'before' example yet.


Andrew



From: concord...@googlegroups.com <concord...@googlegroups.com> on behalf of Tim Wright <t...@tfwright.co.nz>
Sent: Sunday, 30 October 2016 6:54 p.m.
To: Nigel Charman
Cc: Andrew; concordion-dev
Subject: Re: [concordion-dev] Re: Listeners and method hooks on 'before' examples
 
That seems complex.

Andrew: would it be useful for your extensions?

Tim
View Tim Wright’s professional profile on LinkedIn. LinkedIn is the world's largest business network, helping professionals like Tim Wright discover inside connections to recommended job candidates, industry experts, and business partners.

--
You received this message because you are subscribed to a topic in the Google Groups "concordion-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/concordion-dev/p98v3g3Vz5U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to concordion-de...@googlegroups.com.

To post to this group, send email to concord...@googlegroups.com.
Visit this group at https://groups.google.com/group/concordion-dev.
Reply all
Reply to author
Forward
0 new messages