I understand that unit tests must be as isolated as possible, i.e. are self-contained and do not have to rely on outside resources like databases, network access or even the execution of previous unit tests.
However, suppose I want to test class Y. Class Y uses class X. However, I have already a number of unit tests that test class X.
I think that in the unit tests of class Y, I could just assume that class X works properly and use instantiations of it to test class Y (instantiated in the class Y unit tests, so no leftovers or other pollution).
Is this correct? Or do I need to mock class X when testing class Y or do something else entirely? If so or if I should mock class X, what are the reasons for that?
It comes down to how much of a purist you want to be. I would not go crazy and mock class X if it's just another class free of dependencies on external resources like a database etc..
The important thing is that you have full test coverage for your code. IMO it's not a problem if already tested code runs as "trusted code" in other tests.
Is assuming that another unit test has tested the input of the unit code breaking isolation?