The JMockit Tutorial より抜粋 http://jmockit.googlecode.com/svn/trunk/www/tutorial/BehaviorBasedTesting.html


返却値を動的に生成したい

   @Test
   public void someTestMethod(@Mocked final DependencyAbc abc)
   {
      new NonStrictExpectations() {{
         abc.intReturningMethod(anyInt, null);
         result = new Delegate() {
            int aDelegateMethod(int i, String s)
            {
               return i == 1 ? i : s.length();
            }
         };
      }};

      new UnitUnderTest().doSomething();
   }

引数をアルゴリズムでチェックしたい

   @Test
   public void verifyExpectationWithArgumentValidatorForEachInvocation(
      @Mocked final Collaborator mock)
   {
      // Inside tested code:
      new Collaborator().doSomething(0.5, new int[2], "test");

      new Verifications() {{
         mock.doSomething(anyDouble, null, null);
         forEachInvocation = new Object() {
            void validate(double d, int[] i, String s)
            {
               assertTrue(d > 0.0);
               assertEquals(2, i.length);
               assertTrue(s.length() > 1);
            }
         };
      }};
   }

any引数に何が設定されたのか知りたい


Java#xUNIT


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS   sitemap
Last-modified: 2013-11-06 (水) 00:52:25 (3824d)
Short-URL: https://at-sushi.com:443/pukiwiki/index.php?cmd=s&k=196a9f382d
ISBN10
ISBN13
9784061426061