It's not news that testing at the end of the development cycle is susceptible to being not only delayed, but also squeezed due to the fact that the deadline can't be shifted...
But how can you prevent that squeezing from happening?
You need to start thinking about shifting testing left; work out how you can start adding value earlier in the development cycle before the test phase even begins.
For example, question the requirements (or Acceptance Criteria) before any code is written to identify gaps in them or where they are just incorrect or ambiguous.
With this approach, you start to discover that testing is far more than testing a delivered system against predefined requirements.
Once the scales have been lifted from your eyes, you'll find it hard to go back!