Jbehave : GivenStories in the end of execution - jbehave

I'm using a GivenStories for executing Login scenario which is located in different story.
I was wondering if there is a way to use something similar in order to execute a logout story which is also located in different story than one I actually executing.
I know that I can do some tricks with #before/after annotations , but the question is if I can execute a "post" story
Thanks

Based on the jBehave annotation documentation a post story step can be implemented by annotating a step class method with #AfterStory (or #AfterStories if you want to execute only after all stories complete). The #AfterStory method will execute regardless of whether your executing story contains a step from the related step class (i.e. is guaranteed to execute after every story - see below for restricting to given stories).
The #BeforeStory and #AfterStory annotations allow the corresponding
methods to be executed before and after each story, either a
GivenStory or not:
#AfterStory // equivalent to #AfterStory(uponGivenStory=false)
public void afterStory() {
// ...
}
#AfterStory(uponGivenStory=true)
public void afterGivenStory() {
// ...
}

This is the answer I got from the jbehave dev channel.
Hi,
there is no such mechanism, but you could:
use the Lifecycle to execute steps (not stories) after the execution
of a scenario (executed after each scenario) have a final scenario
which invokes the given stories

Related

How to write the test method for the following code?

I have code for this before update trigger and I have to write the test method for it. I am completely new to apex and this is the first trigger I wrote but not getting how to write test method for it.
Code
The screenshot doesn't provide much of the details, but I am writing the test class based on the info you have shared.
Tweak the code based on how you have implemented the trigger.
#isTest
private class StatusCloseDateTest {
#isTest static void testStatusCloseDate() {
yourObjAPIName__c rectoupdate = new yourObjAPIName__c();
rectoupdate.name = 'testValue';
/* based on the type of trigger (insert,update,delete) you wrote
perform the dml action.
EG:insert rectoupdate/update rectoupdate/delete rectoupdate
*/
insert rectoupdate;
/* when you perform this dml operation, the trigger will get
invoked and the code you have written in the trigger will
be covered by this test class method.
*/
}
}
Run the test methods in this class.
In the Developer Console, click Test | New Run.
Under Test Classes, click "StatusCloseDateTest".
To add all the test methods in the "StatusCloseDateTest" class to the test run, click Add Selected.
Click Run.
For more details refer : Trailhead

Nunit Test Order - Single Test - Multiple Orders

For Nunit Test order, is it possible to have multiple order positions for a test, such as [Test, Order(3, 10, #...)]?
Scenario - I am automating a multi-page online application using end-to-end ordered tests (with Asserts verifying entered info), and I want to verify info on previous pages is still there - saved - when I click Back button (basically, reverse-check the end-to-end starting from last page of application using Back button to navigate). I want to reuse Asserts already there instead of rewriting the same ones again.
I have tried the following as an experiment, which generate build error CS1729 - 'type' does not contain a constructor that takes 'number' arguments:
[Test, Order(66, 67)]
**
[Test, Order(66)(67)]
**
[Test, Order(66), Order(67)]
**
[Test, Order(66)]
[Test, Order(67)]
I Googled this, and I don't see anything that does the above, so I assume it is not possible, but want to confirm. I cannot remove the Order attribute as that's part of the requirement for this test.
No, that's not possible. The OrderAttribute sets a property, which is a simple integer.
To simulate the effect you want, you may do the following:
Extract all the code of the test in question to a separate method, called by the test. It should have the same signature as the test.
Replicate the test you want to repeat, using a different name.
Assign a different order attribute to each test.
Assuming a signature of void TestMethod() it will look something like this...
[Test, Order(66)]
public void MyTest66()
{
MyRealTest();
}
[Test, Order(67)]
public void MyTest67()
{
MyRealTest();
}
private void MyRealTest()
{
// Your actual test code goes here
}
Note... this is a really ugly hack but the only guaranteed way I can think of to do what you indicate is required.

Any way to ensure frisby.js test API calls go in sequential order?

I'm trying a simple sequence of tests on an API:
Create a user resource with a POST
Request the user resource with a GET
Delete the user resource with a DELETE
I've a single frisby test spec file mytest_spec.js. I've broken the test into 3 discrete steps, each with their own toss() like:
f1 = frisby.create("Create");
f1.post(post_url, {user_id: 1});
f1.expectStatus(201);
f1.toss();
// stuff...
f2 = frisby.create("Get");
f2.get(get_url);
f2.expectStatus(200);
f2.toss();
//Stuff...
f3 = frisby.create("delete");
f3.get(delete_url);
f3.expectStatus(200);
f3.toss();
Pretty basic stuff, right. However, there is no guarantee they'll execute in order as far as I can tell as they're asynchronous, so I might get a 404 on test 2 or 3 if the user doesn't exist by the time they run.
Does anyone know the correct way to create sequential tests in Frisby?
As you correctly pointed out, Frisby.js is asynchronous. There are several approaches to force it to run more synchronously. The easiest but not the cleanest one is to use .after(() -> ... you can find more about after() in Fisby.js docs.

How to make EF log sql queries globally?

How do I "tell" EF to log queries globally? I was reading this blog post: EF logging which tells in general how to log sql queries. But I still have a few questions regarding this logger.
Where would I need to place this line context.Database.Log = s =>
logger.Log("EFApp", s);?
Can it be globally set? Or do I have to place it everywhere I do DB
operations?
In the "Failed execution" section, the blogger wrote that, and I
quote:
For commands that fail by throwing an exception, the output contains the message from the exception.
Will this be logged too if I don't use the context.Database.Log?
Whenever you want the context to start logging.
It appears to be done on the context object so it should be done every time you create a new context. You could add this line of code in your constructor though to ensure that it is always enabled.
It will not log if you do not enable the logging.
I don't recommend to use that's functionality, because, it hasn't reason to exists in the real case.
Thats it use a lot of to debug code only. But, wether you wanna know more than details ... access link... https://cmatskas.com/logging-and-tracing-with-entity-framework-6/
In this case you can put code like this
public void Mylog()
{
//Thats a delegate where you can set this property to log using
//delegate type Action, see the code below
context.Database.Log = k=>Console.Write("Any query SQL")
//Or
context.Database.Log = k=>Test("Any query SQL")
}
public void Test(string x){
Console.Write(x)
}
I hope thats useufull

How do I put a specific order to Jbehave story execution?

When you submit sorties to Jbehave with
#Override
public InjectableStepsFactory stepsFactory()
{
return new InstanceStepsFactory(configuration(),
new LoginSteps(), new PreferencesSteps(), new BetterSteps());
}
They are executed in BetterSteps, LoginSteps, PreferencesStpes fasion.
How do I make these classes having scenarios execute in a custom order which is not alphabetical?
Say LoginSteps followed by PreferenceSteps followed by BetterSteps etc?
There is a work around for your problem..
You can make your story name starting from Sn where n is 1,2,3..... like S1_LoginSteps, S2_PreferenceSteps
Jbehave will execute stories alphabetical starting from S1 then S2....
Do I understand you correctly that you have steps with identical or similar patterns in all of these steps classes and want to control which of them are used over others?
If so, have a look at step prioritization here: http://jbehave.org/reference/stable/prioritising-steps.html and apply priorities to your preferred steps.