I think this might be "Sphere" by Michael Crichton.
In the novel, a sphere (an old alien spaceship) is discovered on the bottom of the ocean. There's a team sent to explore, and while they do so, increasingly improbable things happen. it turns out that
the sphere reacts to the things they are imagining, making them real... including fears and subconscious desires or imaginings
when they discover this, there is indeed some speculation that
the sphere may be a test by whichever alien species created it - to see if whoever discovered it would have enough control to not imagine themselves into trouble
Found a (partial) quote for this bit on google books
...let's face it - we didn't handle ourselves very well" Norman noticed she spoke without rancor now, her previous combative edge gone.
"I'm afraid that's true," Norman said. "The sphere was built to test any intelligent life that picked it up, and we simply failed that test."
I recall a quote very similar to the one you mention, where a character denies the above theory, mentioning that some of our deadly technology might seem a test to simpler animals, or a trap, but that isn't what we made it for (I think there were several comparisons, but the bacteria and fuel cell seems very familiar)
"I'm afraid that's true," Norman said."The sphere was built to test whatever intelligent life might pick it up, and we simply failed that test."
"Is that what you think the sphere was made for?" Harry said. "I don't."
"Then what?" Norman said.
"Well," Harry said, "look at it this way: Suppose you were an intelligent bacterium floating in space, and you came upon one of our communication satellites, in orbit around the Earth. You would think, What a strange, alien object this is, let's explore it. Suppose you opened it up and crawled inside. You would find it very interesting in there, with lots of huge things to puzzle over. But eventually you might climb into one of the fuel cells, and the hydrogen would kill you. And your last thought would be: This alien device was obviously made to test bacterial intelligence and to kill us if we make a false step.
"Now, that would be correct from the standpoint of the dying bacterium. But that wouldn't be correct at all from the standpoint of the beings who made the satellite. From our point of view, the communications satellite has nothing to do with intelligent bacteria. We don't even know that there are intelligent bacteria out there. We're just trying to communicate, and we've made what we consider a quite ordinary device to do it."
This was also made into a movie in 1998