2017-03-09 6 views
0

私はテストランナーとしてjUnitを使用するキュウリのテストケースを作成しています。私は両方のオブジェクトが同じ要素を持っている場合にtrueをアサートするメソッドを使用しています。containsOnlyElementsOfは2つのオブジェクトを渡すとfalseを返します

assertThat(obj1).containsOnlyElementsOf(obj2) 

しかし、両方のオブジェクトがまったく同じ要素と同じ値を持っていても、trueを返すわけではありません。ここにスタックトレースがあります。

java.lang.AssertionError: 
Expecting: 
<[[email protected], 
[email protected], 
[email protected], 
[email protected]]> 
to contain only: 
<[[email protected], 
[email protected], 
[email protected], 
[email protected]]> 
elements not found: 
<[[email protected], 
[email protected], 
[email protected], 
[email protected]]> 
and elements not expected: 
<[[email protected], 
[email protected], 
[email protected], 
[email protected]]> 

at      com.solambda.kronos.timesheet.steps.TimesheetSteps.i_get_the_following_timesheet s(TimesheetSteps.java:806) 
at ✽.Then I get the following timesheets: (com/solambda/kronos/timesheet/Worker_list.feature:43) 

似たような問題に直面したことがありますか?私が何かを逃しているか、適切にやり遂げていないところであれば教えてください。

+0

これらのアサーションメソッドは、通常、要素( 'TimesheetListRowDto')とそれらの' equals'メソッドを比較することによって機能します。 'TimesheetListRowDto'の' equals'メソッドはどのように実装されていますか? –

+0

@ThomasKlägerは、ApacheのコモンズからEqualsBuilder()を使用しています。 –

+0

はい。問題はequalsメソッドで発生しました。このメソッドが正しく機能するように実装する必要があります –

答えて

0

containsOnlyElementsOfのライブラリとしてassertj-coreをライブラリとして使用することを前提としています。

このメソッドcontainsOnlyElementsOfは、イテラブルが同じオブジェクトを持っているかどうかをチェックします。

関連する問題