Should the test verify the correctness of the data? How to check skillfully?

question

in the article "the practice of testing the Pyramid", there is a saying:

. Do not couple the internal structure of the implementation code in your unit tests. To test observable behavior. You should think like this:
if my input is x and y, will the output be z?

even if the result is "z" (eg.) "the audit result has been saved"), how can I make sure that it is executed correctly internally?

give an example

the verification methods I can think of are as follows:

write a top-up test and verify the return data of the "get my balance" interface before and after the call to ensure that my balance has really increased.
as a result, the recharge interface and the current "get balance" result in the coupling of the test code.

once this happens, modifying the return structure of the get balance interface will face the paralysis of the whole related test code.

this is obviously inappropriate. So how exactly should the "right test" be written? To what extent can it be considered qualified?

Nov.25,2021

each unit test is only used to test the correctness of a function or function. As for any implementation in the function, as long as the test gets the desired results.
as for ensuring the correctness of the internal function of the function, you need some patterns to implement.
for example, to test a method of adding two numbers.

// recharge.test.js
import post from './post'

const deposit = { money: 10 }
// post, api 
post.mockImplementation(() => {
  return {
    post: (url, { data }) => {
      deposit.money += data.money
      return true
    },
  }
})
it('', () => {
  const money = 10
  recharge(money)
  expect(deposit.money).toBe(20)
})
it('', () => {
  const money = 10
  expect(recharge(money)).toBe(true)
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38762-2ae5c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38762-2ae5c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?