Different behavior in tests

Hello,

I need help.
I have the block of code below, and I need know if can use the statement tests[" coverages code »»» " in several tests. If I use the statement, the postman not return all tests.

Result with same statement:
image

Result with different statement:

Hey @apatriciachaves,

It’s a little difficult to understand the context to your question.

Are you able to expand on this more please?

Also, could you post your full code rather than an image of it, it makes it easier for other community members to see it and help you out. :slight_smile:

Hi @dannydainton ,

I’ll try to explain my question better :slight_smile:

Considering this block of code:

if(i == 0)
{
	let covarages_code = ["43","44","0"];
	for(let j=0; j<length_coverages; j++)
	{
	  tests["coverages code " »»» " + resBody.quotationsGroup[i].members[0].memberPersons[0].coveragePackage.coverages[j].code] = resBody.quotationsGroup[i].members[0].memberPersons[0].coveragePackage.coverages[j].code == covarages_code[j];
	}
}
else if (i == 1)
{
let covarages_code = ["5","15","43","44","0"];
	for(let j=0; j<length_coverages; j++)
	{
	  tests["coverages code " »»» " + resBody.quotationsGroup[i].members[0].memberPersons[0].coveragePackage.coverages[j].code] = resBody.quotationsGroup[i].members[0].memberPersons[0].coveragePackage.coverages[j].code == covarages_code[j];
	}
}

In the test step the string “coverages code”, and this test is inside a for, which in turn is inside an if.

When i == 0, the test will return “43”, “44”, “0”, in the meantime when i == 1 will only return “5” and “15”, since the “43”, “44”, “0” has already been returned at i == 0.

Considering this block of code:

if(i == 0)
    {
    	let covarages_code = ["43","44","0"];
    	for(let j=0; j<length_coverages; j++)
    	{
    	  tests["coverages code " + i + " »»» " + resBody.quotationsGroup[i].members[0].memberPersons[0].coveragePackage.coverages[j].code] = resBody.quotationsGroup[i].members[0].memberPersons[0].coveragePackage.coverages[j].code == covarages_code[j];
    	}
    }
    else if (i == 1)
    {
    let covarages_code = ["5","15","43","44","0"];
    	for(let j=0; j<length_coverages; j++)
    	{
    	  tests["coverages code " + i + " »»» " + resBody.quotationsGroup[i].members[0].memberPersons[0].coveragePackage.coverages[j].code] = resBody.quotationsGroup[i].members[0].memberPersons[0].coveragePackage.coverages[j].code == covarages_code[j];
    	}
    }

In the test step the string is concatenated with the “i” (tests [“coverages code” + i + "), which already causes when i == 1 returns the 5 values of the array.

I’m unsure what you’re trying to achieve without seeing an example response body.

I’m assuming you’re looping through an array, and inside that are other arrays? And you want to test specific things in each nested array??

Just a thing to note, which I’m sure you’ve already figured out by now - but just incase.
If I loop through an array and run a test, it’ll show as ONE test result in the test report.

But if I place the test, not the assertion, inside the loop it’ll be shown several times in the report:

I can make the test names unique in the report, something like:

1 Like

@pfarrell,

The response body is:

Can someone help me, please?

I posted about how to deal with an array of objects or nested items.

If you want me to deal with your response body directly, can you reply with your raw JSON response, something that I can paste into Postman to debug.

Cheers