Junit测试,不会停止在ArrayList返回类型方法上运行

时间:2012-12-18 19:01:53

标签: java return junit4

您好我正在尝试测试一个方法,该方法返回ArrayListjunit 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());
    }

Repo.class

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;
    }

Controller.class

@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)

1 个答案:

答案 0 :(得分:2)

以下几行:

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

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