# Different behavior in tests

**URL:** <https://community.postman.com/t/different-behavior-in-tests/5626>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [May 28, 2019, 9:26am UTC](https://community.postman.com/t/different-behavior-in-tests/5626 "2019-05-28T09:26:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![apatriciachaves](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@apatriciachaves](https://community.postman.com/u/apatriciachaves)\
**Post date:** [May 28, 2019, 9:26am UTC](https://community.postman.com/t/different-behavior-in-tests/5626/1 "2019-05-28T09:26:15Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/b/b7bce51901ced07d0dfaa5adb4832c8fdb56d77f.png)

Result with same statement:  
 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/e/e7a2359d743de25958881f94e6637dceabda5f5a.png)

Result with different statement:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/7/a/7a0bae6a7e3b7af468f874dc6ff3c16e77966742.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [May 28, 2019, 1:07pm UTC](https://community.postman.com/t/different-behavior-in-tests/5626/2 "2019-05-28T13:07:43Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![apatriciachaves](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@apatriciachaves](https://community.postman.com/u/apatriciachaves)\
**Post date:** [May 31, 2019, 10:30am UTC](https://community.postman.com/t/different-behavior-in-tests/5626/3 "2019-05-31T10:30:15Z")

</div>

Hi @danny-dainton ,

I’ll try to explain my question better 🙂

**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.

---

<div class="post-metadata">

**Author:** ![postman-paul540](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/postman-paul540/32/149_2.png) [@postman-paul540](https://community.postman.com/u/postman-paul540)\
**Post date:** [May 31, 2019, 12:11pm UTC](https://community.postman.com/t/different-behavior-in-tests/5626/4 "2019-05-31T12:11:20Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/1/7/1765e993a328e4312a2471af1b5ac46e1a6e1830.png)

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

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/d/d6b4cbdafddb081a3ae00511430cd706ab1960c1.png)

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

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/d/dfc2715f5eea5b473165459c47e87a0ea5fcc1cd.png)

---

<div class="post-metadata">

**Author:** ![apatriciachaves](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@apatriciachaves](https://community.postman.com/u/apatriciachaves)\
**Post date:** [May 31, 2019, 2:49pm UTC](https://community.postman.com/t/different-behavior-in-tests/5626/5 "2019-05-31T14:49:11Z")

</div>

@postman-paul540,

The response body is:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/0/2/02c117c0af88322de67cda55fc362586447203e8.png)

---

<div class="post-metadata">

**Author:** ![apatriciachaves](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@apatriciachaves](https://community.postman.com/u/apatriciachaves)\
**Post date:** [June 11, 2019, 9:02am UTC](https://community.postman.com/t/different-behavior-in-tests/5626/6 "2019-06-11T09:02:04Z")

</div>

Can someone help me, please?

---

<div class="post-metadata">

**Author:** ![postman-paul540](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/postman-paul540/32/149_2.png) [@postman-paul540](https://community.postman.com/u/postman-paul540)\
**Post date:** [June 11, 2019, 3:24pm UTC](https://community.postman.com/t/different-behavior-in-tests/5626/7 "2019-06-11T15:24:57Z")

</div>

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
