Each Assert allow to define error message which will be printed out in case of assert failure but can I somehow provide a message which will be outputed in case of successful test run?
I just use Console.WriteLine( "Your message here" ); which will be directed to the NUnit output so you can see Test passed messages
You can use the Assert.Pass utility method.
You've said that you want this information for use by your continuous integration environment. Presumably your CI environment is using the NUnit-console Runner?
If so then I recommend making use of the XML output generated from each test run, and example of which can be found here.
The XML output contains results for each and every test. You haven't said which CI server you're using, but it should be straightforward to build a step into your build process to import this XML and mine it for the stats you need.
You should handle the NUnit.Framework.SuccessException and print the message:
try
{
// assert
Assert.Pass(sOutput);
}
catch (SuccessException ex)
{
Console.WriteLine(ex.Message);
return;
}
As a result you should get the output message under clicking Output:
Related
I have an application using React and axios, and I want to this the following behvior:
Fill a form
submit form
Success message shows
Fill the form again
submit form
While the request is made, the success message should not be showing**
request finish, success message shows again
**the problem is to test this step (6)
I'm using axios-mock-adapter to mock axios. I tried the following approach:
axiosMock
.onPost('/api/auth/alteracaoSenha').replyOnce(204)
.onPost('/api/auth/alteracaoSenha').replyOnce(() => {
expect(screen.queryByText('Success message')).not.toBeInTheDocument()
return [204]
})
When I try this, it works fine. But, if I remove the code that reset the success message to see if the test broke, the test continues to pass.
What I found is that the expect throws an error, but the axios mock catch this error and just return it to the API :/ So the expect line that should file, did not break the test.
Is there any other option to do that test?
I would like to uses jmeter for api functional testing, the jmeter dashboard reporting is not ideal for functional testing.
I have attempted to integrate extent 2.41.2 reporting with groovy script that validates responses (http and expected response code).
I have attempted to use the idea given in Using extentreports for jmeter test results
However that has failed. I used a js2322 assertion to check for valid responses, but then I get errors whenever attempt to run.
I'm not sure whether it should be setup as post processor step instead of an assertion.
Has anyone got any ideas on how this can be achieved?
You can assert result by using prev which is SampleResult:
prev - (SampleResult) - gives access to the previous SampleResult (if any)
Here's example of checking token exists in response and if not return relevant assertion:
import org.apache.jmeter.assertions.AssertionResult;
boolean assertToken = prev.getResponseDataAsString().contains("token");
prev.setSuccessful(assertToken);
if (!assertToken) {
AssertionResult assertionResult = new AssertionResult("Assertion expected to contain token")
assertionResult.setFailureMessage("Assertion failure message: Test failed: text expected to contain /token/");
assertionResult.setFailure(true);
prev.addAssertionResult(assertionResult);
}
I'm trying to validate whether error messages returned by API are proper or not.
So, I stored all local error message strings in HashMap errorMessage
.doIf(errorMessages.size()>1) {
exec(session => {
assert(ResponseJSON.contains(errorMessages.get("errorMessage1")))
for ((k,v)<- errorMessages){
assert(ResponseJSON.contains(v))
}
}
I could see the error on console as
hook-3' crashed with 'java.lang.AssertionError: assertion failed', forwarding to the next one
But, the Gatling scenarios are not failing here, what is I'm missing ?
Try using an exitHereIfFailed to exit the scenario.
A Gatling scenario with an exec chain. After a request, returned data is saved. Later it's processed and depending on the processing result, it should either fail or pass the test.
This seems like the simplest possible scenario, yet I can't find any reliable info how to fail a test from within an exec block. assert breaks the scenario and seemingly Gatling (as in: the exception throw doesn't just fail the test).
Example:
// The scenario consists of a single test with two exec creating the execChain
val scn = scenario("MyAwesomeScenario").exec(reportableTest(
// Send the request
exec(http("127.0.0.1/Request").get(requestUrl).check(status.is(200)).check(bodyString.saveAs("MyData")
// Process the data
.exec(session => {
assert(processData(session.attributes("MyData")) == true, "Invalid data");
})
))
Above the scenario somewhere along the line "guardian failed, shutting down system".
Now this seems a useful, often-used thing to do - I'm possibly missing something simple. How to do it?
You have to abide by Gatling APIs.
With checks, you don't "fail" the test, but the request. If you're looking for failing the whole test, you should have a look at the Assertions API and the Jenkins plugin.
You can only perform a Check at the request site, not later. One of the very good reasons is that if you store the bodyString in the Sessions like you're doing, you'll end using a lot of memory and maybe crashing (still referenced, so not garbage collectable). You have to perform your processData in the check, typically in the transform optional step.
were you looking for something like
.exec(http("getRequest")
.get("/request/123")
.headers(headers)
.check(status.is(200))
.check(jsonPath("$.request_id").is("123")))
Since the edit queue is already full.
This is already resolved in the new version of Gatling. Release 3.4.0
They added
exitHereIf
exitHereIf("${myBoolean}")
exitHereIf(session => true)
Make the user exit the scenario from this point if the condition holds. Condition parameter is an Expression[Boolean].
I implemented something using exitHereIfFailed that sounds like exactly what you were trying to accomplish. I normally use this after a virtual user attempts to sign in.
exitHereIfFailed is used this way
val scn = scenario("MyAwesomeScenario")
.exec(http("Get data from endpoint 1")
.get(request1Url)
.check(status.is(200))
.check(bodyString.saveAs("MyData"))
.check(processData(session.attributes("MyData")).is(true)))
.exitHereIfFailed // If we weren't able to get the data, don't continue
.exec(http("Send the data to endpoint 2")
.post(request2Url)
.body(StringBody("${MyData}"))
This scenario will abort gracefully at exitHereIfFailed if any of the checks prior to exitHereIfFailed have failed.
How do you customize the Gateway Errors that pop up when a customer's credit card is declined.
Example would be "Payment transaction failed. Reason Gateway error: An error occurred during processing. Please try again."
We're using Authorize.net if that makes a difference. To clarify, we aren't looking to get rid of them, just modify the language in them.
Copy the file app/code/core/Mage/Paygate/Model/Authorizenet.php to local. Then find this (line 1334):
protected function _wrapGatewayError($text)
{
return Mage::helper('paygate')->__('Gateway error: %s', $text);
}
and replace with this:
protected function _wrapGatewayError($text)
{
if($text == 'This transaction has been declined.') {
$text = 'Custom message here.';
}
return Mage::helper('paygate')->__('Gateway error: %s', $text);
}
I know this is an old question, but I will leave this here for the future in case if someone runs into this.
The _wrapGatewayError() method already uses a helper to output the message, so why not just translate the message?
Create (or edit) your localization/translation file in app/design/frontend/{package_name}/{theme_name}/locale/en_US/translate.csv. You can check the active package_name and theme_name in System / Configuration / Design (under 'General').
Add the messages you are changing to that file in this format: "Old text - message you want to change", "New message".
In your case, it will be something like this:
"Payment transaction failed. Reason Gateway error: An error occurred during processing. Please try again.", "Your custom message"
How it works: whenever a helper is used to output the "Payment translation failed. ...", the system will find the translation file (translate.csv) and will change the message to your custom one.
Please don't modify core files. It creates a mess, interferes with patches, and makes debugging harder. You can extend them if you need to. See Overriding Magento blocks, models, helpers and controllers