How can I make the @Resource annotation work?
You must add the @Resource annotation to a servlet, filter or other supported class. The servlet 3.0 specification states that containers are not required to perform annotation injection on classes that do not implement any of the following interfaces.
javax.servlet.Servlet
javax.servlet.Filter
javax.servlet.ServletContextListener
javax.servlet.ServletContextAttributeListener
javax.servlet.ServletRequestListener
javax.servlet.ServletRequestAttributeListener
javax.servlet.http.HttpSessionListener
javax.servlet.http.HttpSessionAttributeListener
javax.servlet.AsyncListener
Since your test class does not implement any of these interfaces I would not expect resource injection to work.