java Eclipse Maven项目外观

px9o7tmv  于 2023-03-28  发布在  Java
关注(0)|答案(1)|浏览(110)

我有一个动态的web项目,我配置为使用Maven。现在我试图运行单元测试登录servlet(使用JUnit,不使用spring),但eclipse总是在我尝试运行测试用例时给我同样的错误。错误是:'在以下期间发生内部错误:“正在启动LoginPatientTest”。无法调用“org.eclipse.m2e.core.project.IMavenProjectFacade.getMavenProject(org. eclipse.core.runtime.IProgressMonitor)”,因为“facade”为空。我的测试用例是:

package control;

import static org.mockito.Mockito.*;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import model.ProfileManager;
import model.Bean.PatientBean;

public class LoginPatientTest {

    String fiscal_code;
    String user_password;
    
    @Before
    public void setUp() throws Exception {
        fiscal_code = "aaaaaaa";
        user_password = "bbbbb";
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void testPresent() throws IOException, ServletException{
           HttpServletRequest req = mock(HttpServletRequest.class);
           HttpServletResponse res = mock(HttpServletResponse.class);
           HttpSession session = mock(HttpSession.class);
           when(req.getSession()).thenReturn(session);
           ProfileManager pm = mock(ProfileManager.class);
           when(pm.ReturnPatientByKey(fiscal_code, user_password)).thenReturn(new PatientBean());
           LoginPatient servlet = new LoginPatient();
           servlet.doPost(req, res);
        }

}
aurhwmvo

aurhwmvo1#

将工作区切换到另一个工作区,然后返回到原始工作区。
另一种解决方案:重新启动eclipse。

相关问题