In order to get a positive test for the virus, enough of it must be forming in an infected person at the time of assay. This can actually take a number of days after infection. You have the disease, but for days can test negative (1). If one were on a very long flight, say 15 hours, it is possible that they could test negative at the start of the flight, and test positive at the end, if they are on the verge of "crossing-over" : negative-to-positive when they boarded the flight. It would largely depend on the rate of viral replication in a given individual.
Looking up the "longest commercial airline flight", it came back as:
"Singapore Airlines' direct flight from Singapore to Newark, New Jersey, is currently the longest flight in the world, lasting around 18 hours and 30 minutes and traveling 9,534 miles."
People using such long fights, lasting many hours, certainly run a risk (likely slight), of contracting the disease even if all people tested negative minutes before wheels-up. The actual risk would be variable depending on the origin of the flight and all those aboard, the number of people on board, and other mitigating or exacerbating factors.
Best solution: Don't take long flights.
The longer the flight, the greater the risk. In some infected passengers who later who may end up in the ER, the virus could multiply at an exponential rate, meaning the carrier could become infective half way though an 18 hour flight. While this seems fanciful, this virus is so strange that until proven otherwise, many experts would agree that it is real possibility. Once an individual tests positive, they could easily become infective within hours. On a long flight, that could be many hours of increasing exposure as the virus replicates.
(1)
https://medical.mit.edu/covid-19-updates/2020/07/when-should-i-be-tested