Well, the fruits we eat today are the results of centuries of controlled breeding. Most wild fruits aren't that tempting for humans.
The fruits of various plants are used for seed dispersal by having hooks and thorns that get stuck in the fur animals or by being tasty, just to give two examples. Plants that developed mechanisms that meant that their seeds were able to get further away from the mother plant, even if it was just a tiny bit, gained an advantage and were more likely to spread and survive.
The thing we most often call fruits are parts we and other animals eat, and then the seeds are dispersed unharmed together with excrement, which gives a good boost when it comes to growing. Some fruits are buried by animals that hoard and are thus "planted". Fruits that were tasty, if only a little, were more likely to get eaten or saved as food. The plants never chose to produce tasty fruits, but the ones that had tastier fruits than the others were more likely to survive and spread.
When it comes to poisonous fruits that are toxic to humans, they are often tolerated by other species.
To use a simplified fictional example:
1. A plant produces bitter fruits. None of the unicorns want to eat it.
2. A mutation blocks the part that produces the bitterness and thus the fruit tastes more neutral. A few unicorns start eating it and the fruit with the neutral taste becomes the dominant one after many generations.
3. Another mutations leads a big amount of the sugars produced by the plants into the fruits. Now the unicorns all go crazy about it and eat lots of it! Soon the sweet fruit is dominant.