-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a step before transition #254
Comments
Hi @SeanFarrow . Yes, if you have a method named 'Setup,' or ending with 'Context,' it will run before any transition methods, and can be a good place to create the SUT. These rules are codified in the DefaultMethodNameStepScanner. You could potentially replace this scanner if you preferred other method names. |
Hi,
Ok, so, Any method with GivenAttribute or AndGivenAttribute will be executed before the Setup/context method, am I correct? I’ve got a whole bunch of tests I’m porting, and I don’t want to get this wrong as undoing this will be a nightmare.
Cheers
Sean.
From: Michael Whelan [mailto:notifications@github.com]
Sent: Tuesday, June 20, 2017 09:55
To: TestStack/TestStack.BDDfy <TestStack.BDDfy@noreply.github.com>
Cc: Sean Farrow <sean.farrow@seanfarrow.co.uk>; Mention <mention@noreply.github.com>
Subject: Re: [TestStack/TestStack.BDDfy] Adding a step before transition (#254)
Hi @SeanFarrow<https://github.com/seanfarrow> . Yes, if you have a method named 'Setup,' or ending with 'Context,' it will run before any transition methods, and can be a good place to create the SUT. These rules are codified in the DefaultMethodNameStepScanner<https://github.com/TestStack/TestStack.BDDfy/blob/master/src/TestStack.BDDfy/Scanners/StepScanners/MethodName/DefaultMethodNameStepScanner.cs>. You could potentially replace this scanner if you preferred other method names.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#254 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABY1fioObQ39wEVUrTT82-VstkMHXUCwks5sF4jsgaJpZM4N_N7A>.
|
No, Setup or *Context will run before Given When Then Transitions, then TearDown will run afterwards. There's more info in the docs here. I'd be happy to take a look at some of your JBehave tests and help you get the syntax right for the port to BDDfy, if you have a public repo you could point me at. |
Hi,
Ok, I’m looking for something to run between given and when, not before given.
Unfortunately it’s not a public project.
Any ideas?
Kind regards
Sean.
From: Michael Whelan [mailto:notifications@github.com]
Sent: Tuesday, June 20, 2017 20:00
To: TestStack/TestStack.BDDfy <TestStack.BDDfy@noreply.github.com>
Cc: Sean Farrow <sean.farrow@seanfarrow.co.uk>; Mention <mention@noreply.github.com>
Subject: Re: [TestStack/TestStack.BDDfy] Adding a step before transition (#254)
No, Setup or *Context will run before Given When Then Transitions, then TearDown will run afterwards. There's more info in the docs here<http://teststackbddfy.readthedocs.io/en/latest/#method-naming-conventions-in-reflective-api>.
I'd be happy to take a look at some of your JBehave tests and help you get the syntax right for the port to BDDfy, if you have a public repo you could point me at.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#254 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABY1fgIShXUnI9bZJ8mXGziTa23MZXAXks5sGBa6gaJpZM4N_N7A>.
|
Ah OK, when you said transitions, you meant the When step? I thought you were referring to all the GWT steps but just the When would make sense. Yes, I think this can be done, but it would really help to see an example, even if it's just a made up one. How is it done in JBehave? i.e. What is the functionality of that framework that you are trying to port over? I would be interested to know how 'automatic' you want to make this? If you are just going to have it be a method of every class, then you could just make the final AndGiven method create the SUT, or you could have a When method create the SUT, and an AndWhen method for your When. Neither very elegant, and both would be reported, which I suspect is what you are wanting to avoid? Personally, I like to have a SUT variable that lazily creates the SUT the first time it is called from your scenario. Something like this:
You can override the CreateSut method in each test or you can implement this method to automatically create the SUT from an IoC container or an automocking container. But yeah, it would be good to have an example as there are a number of things we could do. |
Hi Michael,
Sorry this has taken a while but, Take the following:
public class SomethingUnderTest
{
private readonly ISomethingElse _somethingElse;
public SomethingUnderTest(ISomethingElse somethingElse)
{
_somethingElse = somethingElse;
}
public ISomethingElse SomethingElse
{
get { return _somethingElse; }
}
}
public interface ISomethingElse
{
string SayHello();
}
Public class WhenTestingSomethingWithDependencies: BehaviourTest<SomethingUndertest>
{
private ISomethingElse _fake;
protected override void Given()
{
_fake =Substitute.For< ISomethingElse>(); }
}
//The following method is what I’m looking to port.
Protected override SomethingUndertest CreateSystemUnderTest()
{
Return new SomethingUndertest(this._fake);
}
}
I know I could do this in a given step, but it just seems wrong and it violates the srp.
I’m happy to do the work for this, if you tell me what is needed.
Cheers
Sean.
From: Michael Whelan [mailto:notifications@github.com]
Sent: Tuesday, June 20, 2017 23:25
To: TestStack/TestStack.BDDfy <TestStack.BDDfy@noreply.github.com>
Cc: Sean Farrow <sean.farrow@seanfarrow.co.uk>; Mention <mention@noreply.github.com>
Subject: Re: [TestStack/TestStack.BDDfy] Adding a step before transition (#254)
Ah OK, when you said transitions, you meant the When step? I thought you were referring to all the GWT steps but just the When would make sense. Yes, I think this can be done, but it would really help to see an example, even if it's just a made up one.
How is it done in JBehave? i.e. What is the functionality of that framework that you are trying to port over?
I would be interested to know how 'automatic' you want to make this? If you are just going to have it be a method of every class, then you could just make the final AndGiven method create the SUT, or you could have a When method create the SUT, and an AndWhen method for your When. Neither very elegant, and both would be reported, which I suspect is what you are wanting to avoid?
Personally, I like to have a SUT variable that lazily creates the SUT the first time it is called from your scenario. Something like this:
public abstract class ScenarioFor<T>
{
private T _sut;
public T SUT
{
get
{
if (_sut == null)
{
_sut = CreateSut<T>();
}
return _sut;
}
}
protected virtual T CreateSut<T>()
{
return default(T);
}
}
You can override the CreateSut method in each test or you can implement this method to automatically create the SUT from an IoC container or an automocking container.
But yeah, it would be good to have an example as there are a number of things we could do.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#254 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABY1fuoGuWtKw8h2CFPJKvDUBRvoDgJVks5sGEazgaJpZM4N_N7A>.
|
Hi,
I'm migrating code from JustBehave and would like to add a step to run before any transition steps (it's not really a given as it creates the class under test.) Is there anyway of doing this without modifying the ExecutionOrder enum? Creating the class under test in a given step just seems wrong to me!
Alternativdely, if I make the changes, would this be accepted as a PR?
The text was updated successfully, but these errors were encountered: