2017-11-23 9 views
1

내가 정의 LinkedList의 방법을 테스트 (JUnit을 테스트) 내 개인 추가를위한 가짜 비트 맵 이미지를 생성하고 얻을 필요가 JUnit을 테스트 안드로이드 스튜디오에서 null을 반환 Bitmap.CreateBitmap하지만 Bitmap.createBitmap 오류 반환 :

을 java.lang.RuntimeException : android.graphics.Bitmap의 createBitmap 메소드가 조롱되지 않았습니다.

public class TicketsIteratorTest { 

    Bitmap img_Bmp; 
    TicketsIterator<Bitmap> TicketsList = new TicketsIterator(); 

    /* 
    * Test for the add e get methods, check if the element just insert it's the same of the one just extract. 
    */ 
    @Test 
    public void Add_n_Get() throws Exception { 
     int i = 0, numIMG = 100; 
     Bitmap[] IMG_Generated; 
     IMG_Generated = new Bitmap[numIMG]; 

     // Generate numIMG of imagine to insert into the Iterator and it save each one of it into an 
     // Bitmap array usefull for testing of the get method 
     while (i <= numIMG) { 
      // Generation of the fake Ticket Bitmap 
      try { 
       img_Bmp = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); 

       IMG_Generated[i] = img_Bmp; 

      } catch (Exception e) { 
       // Print the cause of the error just generated 
       e.getCause().printStackTrace(); 
      } 

      // Addition of the imagine just created 
      TicketsList.add(img_Bmp); 

      i++; 
     } 

     // Test if the imagine inserted it is correct 
     while (i <= numIMG) { 
      assertTrue(IMG_Generated[i] == TicketsList.get(IMG_Generated[i])); 
      i++; 
     } 
    } 

이 도움을 주셔서 감사합니다 :

내 JUnitTest의 코드입니다.

답변

0

정기적 인 단위 테스트 또는 Android 테스트에서 이것을 사용하고 있습니까? 일반 유닛 테스트에서 이것을 호출하면, 안드로이드 클래스는 빈/널 구현으로 대체 될 것입니다. 즉, Bitmap.createBitmap()을 호출하면 매개 변수 등을 확인하지 않고도 항상 null이 반환됩니다.

Bitmap과 Base64OutputStream을 사용하여 비슷한 문제가 발생했습니다. 아무것도 뒤에 완벽하게 작동하는 것 같습니다.) 클래스가 Android 프레임 워크가 아닌지 여부를 확인할 때마다 비슷한 문제가 있는지 확인합니다. 문제의 원인 일 가능성이 큽니다.

그게 내가 당신을 도울 수 있기를 바랍니다. 필자는 PowerMock을 사용하고 있으며 비트 맵 모의 인스턴스를 반환하기 위해 Bitmap 클래스를 조롱했습니다.

안부,

다리우스 Wiechecki