2017-11-23 2 views
1

をnullを返しBitmap.CreateBitmap:は、私がテスト(JUnitのテスト)私の個人的なアドオンのために偽のビットマップイメージを作成し、カスタムのLinkedListのメソッドを取得する必要がありますが、Bitmap.createBitmapがエラーを返すのJUnitテストのAndroid Studioで

java.lang.RuntimeException:android.graphics.BitmapのメソッドcreateBitmapが嘲笑されていない

これは私のJUnitTestのコードです:

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

は助けてくれてありがとう。

答えて

0

通常の単体テストやAndroidテストでこれを使用していますか?通常の単体テストから呼び出す場合、アンドロイドクラスは空/ヌル実装に置き換えられます。つまり、Bitmap.createBitmap()の呼び出しは、あなたのパラメータなどをチェックしなくても常にnullを返します。

BitmapとBase64OutputStreamでこれまで同様の問題が発生しました。何も後ろから起こっていることを除いて、完全に正常に動作しているように見えます;)クラスがAndroidフレームワークでないかどうかを確認するときはいつでも同様の動作が確認されます - これはおそらく問題の原因になります。

私はそれが私があなたを助けることができたことを願っています。私はPowerMockを使用しており、私の場合はビットマップモックインスタンスを返すためにBitmapクラスを嘲笑しています。

よろしく、

ダリウスWiechecki

関連する問題