The North Eastern Railway’s EE1 electric loco 13 spent 28 years doing pretty much nothing apart from pottering up and down on test trains.
I think that will be difficult to beat. No 13 was built in 1922 for the North Eastern Railway's planned electrification of the York to Newcastle line, which was shelved after the Grouping. It may have done some test runs on the Newport to Shildon line (electrified in 1915 and de-electrified in the late 1930s) but it never operated in service.
Like all ex-NER locomotives, it kept its original number on the LNER until the 1946 renumbering, when it became No 6999. BR initially numbered it 26999 and later 26600, but it was scrapped in 1950, along with the Newport-Shildon fleet (NER/LNER 3-12, later LNER 6490-99, BR 26502-11) which had been mothballed in 1935 - there had been a proposal to use them on the Woodhead route but ten extra EM1s (class 76s) were built instead.
So 28 years and never earned its owners a penny in revenue. It would be another 40 years after No 13 was scrapped before the line from York to Newcastle was finally electrified, and then it was on 25kV ac instead of 1.5kV dc.