I would suggest that this is a place for a reasonable DM ruling rather than a strict reading of the rules.
Xanathar's Guide to Everything has this rule for how to deal with spells that target an invalid target:
If you cast a spell on someone or something that can't be affected by the spell, nothing happens to that target, but if you used a spell slot to cast the spell, the slot is still expended. If the spell normally has no effect on a
target that succeeds on a saving throw, the invalid target appears to have succeeded on its saving throw, even though it didn't attempt one (giving no hint that the creature is in fact an invalid target). Otherwise, you perceive that the spell did nothing to the target.
Now, I'd suggest that "the spell did nothing" should not be interpreted to mean literally nothing happens; it merely means the spell's effects don't apply. The spell does no damage to objects, and any other effects don't take place. An eldritch blast of energy splashes across the table, the ray of frost makes a patch of frost appear on the corpse, and so on; it merely deals no damage to the object in question, and the player characters can tell.
But how do we prevent "shoot everything just in case it's a mimic"? By the rules as written, that strategy seems to work. I have a few suggestions, and you could use one or all of them.
Option 1: Interpret spells more broadly.
I could argue that many cantrips are written too strictly to deal only with creatures. If an eldritch blast deals force damage, why should it only be able to hit creatures? Why not use it to try to break an object? Is it really so different from trying to break an object with a maul or war-pick?
As a DM, you should feel free to declare that spells with attack rolls are firing energy into the environment, and that energy can have reasonable effects on the world. Eldritch blasts can gouge or splinter stone, shocking grasp can scorch wood, acid splash can eat through a rope, and so on. As always, feel free to rule that specific damage types can't harm certain objects -- it's reasonable to rule that cold damage doesn't particularly harm stone in the same way that you can't cut a rope with a hammer or break down a door by firing arrows at it.
I've always tried to encourage clever and interesting play from my players, and saying things like "Oh, you can't do that, the energy blast doesn't hurt objects" only discourages coming up with interesting uses for magic.
Option 2: Sir, this is a Wendy's.
If somebody walked into a restaurant and immediately stabbed the table to check if it was a mimic, it would rightfully freak out everyone around them. Spells should be the same way, if not more so because when somebody starts casting spells, your average citizen won't know what it's going to do. Doing this in a town can and should make the PCs the object of intense law enforcement interest, as much as somebody waving a gun around in a Wendy's would -- even if they didn't intend to hurt anybody, it's probably illegal and definitely upsetting.
Similarly, walking through a dungeon hitting every object with an axe as you go would be noisy and slow, and using a spell for the purpose isn't any different. Every monster in a hundred foot radius should know exactly where the players are, with plenty of time to prepare for them, and that has implications for how the game goes.
Option 3: Paranoid much?
I have to ask where this paranoia is coming from. Do you use mimics and other "trap monsters" so often that the players feel justified in attacking every random object just in case? I can certainly see using a strategy like this when they find a random treasure chest sitting alone in an otherwise empty room and have reasonable suspicion that it isn't what it seems, in which case the players should be rewarded for having good intuition.
If this really is an issue, first check yourself and make sure you aren't just throwing these mimic-like monsters at your players too often. Assuming you aren't, the easiest fix may be to simply talk to the players to assure them that your job as DM is to give the players a good, fun story, not to destroy them, and explain that that excessive paranoia is both unnecessary and destructive to the narrative you're mutually building.
It may not work, but open communication is always better than trying to manipulate the players though in-game levers. That just turns it into a power struggle between you and players and a game of "who can out-think whom", which is also known as player-versus-DM gaming. You don't want that (partly because it's a fake anyway -- the DM can always "win" if he wants to.)