0

您好,我正在尝试测试一个返回 anArrayListjunit 4 framework在我指定的测试中冻结的方法。测试

    @Test
    public void testInDebt() {
        AdminController cont = new AdminController();

        Apartment o1 = new Apartment(1, 4, "Maier B", true);
        Apartment o2 = new Apartment(1, 4, "Maier B", false);
        ArrayList<Expense> exp = new ArrayList<>();
        cont.addKeyWithList(o2, exp);

        assertEquals(exp, cont.inDebt());  <<<<<< Problem here  when I call inDebt
//      
//      cont.addKeyWithList(o1, exp);   
//      assertFalse(cont.inDebt().isEmpty());
    }

回购类

public ArrayList<String> inDebt(){
        ArrayList<String> inDebt = new ArrayList<>();
        for (Map.Entry<Apartment, ArrayList<Expense>> entry : mp.entrySet() ) {
            if(entry.getKey().isDebt()){        // Flag like method on the key if  there are debts.
//              System.out.println("Key = " + entry.getKey() + ", Object = " + entry.getValue()); 
                inDebt.add(entry.getKey().getOwner());
            }
        }
        return inDebt;
    }

控制器类

@Override
public ArrayList<String> inDebt() {
    return repo.inDebt();
}

堆栈跟踪

proj_individual [JUnit] 
    org.eclipse.jdt.internal.junit.runner.RemoteTestRunner at localhost:24285   
        Thread [main] (Suspended (entry into method inDebt in AdminController)) 
            AdminController.inDebt() line: 24   
            AdminControllTests.testInDebt() line: 75    
            NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]  
            NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available   
            DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available   
            Method.invoke(Object, Object...) line: not available    
            FrameworkMethod$1.runReflectiveCall() line: 45  
            FrameworkMethod$1(ReflectiveCallable).run() line: 15    
            FrameworkMethod.invokeExplosively(Object, Object...) line: 42   
            InvokeMethod.evaluate() line: 20    
            BlockJUnit4ClassRunner(ParentRunner<T>).runLeaf(Statement, Description, RunNotifier) line: 263  
            BlockJUnit4ClassRunner.runChild(FrameworkMethod, RunNotifier) line: 68  
            BlockJUnit4ClassRunner.runChild(Object, RunNotifier) line: 47   
            ParentRunner$3.run() line: 231  
            ParentRunner$1.schedule(Runnable) line: 60  
            BlockJUnit4ClassRunner(ParentRunner<T>).runChildren(RunNotifier) line: 229  
            ParentRunner<T>.access$000(ParentRunner, RunNotifier) line: 50  
            ParentRunner$2.evaluate() line: 222 
            BlockJUnit4ClassRunner(ParentRunner<T>).run(RunNotifier) line: 300  
            JUnit4TestClassReference(JUnit4TestReference).run(TestExecution) line: 50   
            TestExecution.run(ITestReference[]) line: 38    
            RemoteTestRunner.runTests(String[], String, TestExecution) line: 467    
            RemoteTestRunner.runTests(TestExecution) line: 683  
            RemoteTestRunner.run() line: 390    
            RemoteTestRunner.main(String[]) line: 197   
        Thread [ReaderThread] (Running) 
    C:\Program Files\Java\jre7\bin\javaw.exe (Dec 18, 2012 8:00:03 PM)
4

1 回答 1

2

以下几行:

org.eclipse.jdt.internal.junit.runner.RemoteTestRunner at localhost:24285   
    Thread [main] (Suspended (entry into method inDebt in AdminController))

表明由于在管理控制器中遇到断点,程序的执行被暂停。您可以在测试运行时切换到调试视图以单步执行挂起的线程。

于 2012-12-18T20:28:17.340 回答