How to detect whether a solenoid is actually attached to a MOSFET?
The thing you're asking and what you're trying to do a very different things.

So, a modern ECU is a complex device with literally hundreds of actors and sensors attached. Especially, there will be sensors that observe whether the explosion in the cyclinder happens, there will be gasoline flow sensors, exhaust gas sensors… plenty of data from which an ECU can infer something went wrong during operation of the motor, and quite possibly also specifically that an injector doesn't work. Whether it knows why that injector doesn't work is a different question; I don't think it needs to!

What you're trying to do is a slight bit easier. You're not observing a complete car's drive. You're observing a solenoid.

So, simplest solution I could think of without actually just sensing the current with a shunt resistor, which brings isolation problems:







simulate this circuit &ndash; Schematic created using CircuitLab

In non-operation, the digital input will be reliably high. But the switching on and: especially the switching off impulse as seen through the capacitor will be very different whether there is a solenoid attached or not; you should be able to register that.

Notice that all the component values are examples only; you probably want a smaller C1 if your solenoid is large, and lower-valued resistors. Maybe a pair of TVS diodes might be a good thing, too, to protect your microcontroller – but that really depends on your microcontroller, switching speed, the solenoid, and your ability to detect short pulses. Most microcontrollers can be programmed to register a sudden edge on an input – be it as an interrupt, or as a counter increase – but if yours doesn't, you'll need to poll that input, so that you might miss very short pulses.