I'm developing in Java and using JUnit to test some of my methods. Some of my methods send emails. The emails are actually sent by a separate thread that is spawned. The problem is that whenever I test these methods everything goes fine except that the emails are not actually sent. I've followed the execution through the whole stack and every method related to sending the emails is being called and executed correctly. So I tested the methods outside of JUnit and the emails send fine.
Is the email thread a background (daemon) thread? Perhaps that thread is terminating due to your tests finishing before the emails are sent?
If you put some logging in directly before and after the email is meant to be sent, do those log entries appear?
Do you have anti-virus turned on? I've wasted a couple of hours troubleshooting a similar problem with a silent anti-virus in the background.
If it is a background thread, it is probably being killed silently when the test method finishes. This won't show in the debugger, because you are stepping through.
You might need to write some convenience method in your JUnit test harness that waits at the end of the test method until the mail is actually send. For a quick test, you might put a Thread.sleep() at the end of your test method to see if this helps.
I appreciate all the helpful responses. I tried most of those things. Turns out it just started working. Maybe it was just something with our stack or email server. Kinda lame.