Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
4
Help us understand the problem. What are the problem?

日付のテストは午後にやろう

SimpleDateFormatHHhh は結構な確率で間違えます。
結合テストが軌道に乗ってきた頃に、午後にならないと再現しない謎の不具合が発生します。

// 現在日時: 2021-09-15 13:24:56

DateFormat df1 = new SimpleDateFormat("yyyyMMddHHmmss");
// => 20210915 *13* 2456

DateFormat df2 = new SimpleDateFormat("yyyyMMddhhmmss");
// => 20210915 *01* 2456

面倒なので単体テストでちゃんと検知しましょう。
ということで、午後の日付を入力値にするのがポイントです。

以下はdjUnitでやるときの例。

// 現在日時を固定(超てきとう)
MockObjectManager.addReturnValue(Calendar.class, "getTime", Timestamp.valueOf("2021-09-15 13:24:56"));

// テスト実行&結果の検証
String result = testObj.test();
assertEquals("20210915132456", result);
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
4
Help us understand the problem. What are the problem?