Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[jvm] Snapshots are not being written to disk when there are tests with numbered names

未关闭
#540 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
java, spring-boot
领域
testing

调研方向

首先在 IntelliJ 中使用 Selfie 2.5.3 运行提供的 JUnit 5 ReproduceSelfieBugTest 示例,然后检查针对带编号测试名称的 snapshot 文件是如何写入和排序的。在添加或删除测试并重新运行文件后,foo10、test10 和 testFoo10 仍能始终存在于 .ss 文件中,即表示完成。

由索引模型根据 Issue 内容生成。

描述

bug

There is an issue when creating test methods that are numbered (e.g. test1(), test2(), ...). At some point snapshots of tests are no longer written to disk. I discovered this while writing integration tests for a Spring Boot app that I generically name test1(), test2() etc. because I use @DisplayName anyway.

I cannot disclose the actual code but here is an example test file using JUnit 5, Java 21 and Selfie 2.5.3 that I could reproduce this with:

import com.diffplug.selfie.Selfie;
import org.junit.jupiter.api.Test;

class ReproduceSelfieBugTest {
  //SELFIEWRITE
  @Test
  void test() {
    Selfie.expectSelfie("0").toMatchDisk();
  }

  @Test
  void test1() {
    Selfie.expectSelfie("1").toMatchDisk();
  }

  @Test
  void test2() {
    Selfie.expectSelfie("2").toMatchDisk();
  }

  @Test
  void test3() {
    Selfie.expectSelfie("3").toMatchDisk();
  }

  @Test
  void test4() {
    Selfie.expectSelfie("4").toMatchDisk();
  }

  @Test
  void test5() {
    Selfie.expectSelfie("5").toMatchDisk();
  }

  @Test
  void test6() {
    Selfie.expectSelfie("6").toMatchDisk();
  }

  @Test
  void test7() {
    Selfie.expectSelfie("7").toMatchDisk();
  }

  @Test
  void test8() {
    Selfie.expectSelfie("8").toMatchDisk();
  }

  @Test
  void test9() {
    Selfie.expectSelfie("9").toMatchDisk();
  }

  @Test
  void test10() {
    Selfie.expectSelfie("10").toMatchDisk();
  }

  @Test
  void testFoo() {
    Selfie.expectSelfie("testFoo").toMatchDisk();
  }

  @Test
  void testFoo1() {
    Selfie.expectSelfie("testFoo1").toMatchDisk();
  }

  @Test
  void testFoo2() {
    Selfie.expectSelfie("testFoo2").toMatchDisk();
  }

  @Test
  void testFoo3() {
    Selfie.expectSelfie("testFoo3").toMatchDisk();
  }

  @Test
  void testFoo4() {
    Selfie.expectSelfie("testFoo4").toMatchDisk();
  }

  @Test
  void testFoo5() {
    Selfie.expectSelfie("testFoo5").toMatchDisk();
  }

  @Test
  void testFoo6() {
    Selfie.expectSelfie("testFoo6").toMatchDisk();
  }

  @Test
  void testFoo7() {
    Selfie.expectSelfie("testFoo7").toMatchDisk();
  }

  @Test
  void testFoo8() {
    Selfie.expectSelfie("testFoo8").toMatchDisk();
  }

  @Test
  void testFoo9() {
    Selfie.expectSelfie("testFoo9").toMatchDisk();
  }

  @Test
  void testFoo10() {
    Selfie.expectSelfie("testFoo10").toMatchDisk();
  }

  @Test
  void foo() {
    Selfie.expectSelfie("foo").toMatchDisk();
  }

  @Test
  void foo1() {
    Selfie.expectSelfie("foo1").toMatchDisk();
  }

  @Test
  void foo2() {
    Selfie.expectSelfie("foo2").toMatchDisk();
  }

  @Test
  void foo3() {
    Selfie.expectSelfie("foo3").toMatchDisk();
  }

  @Test
  void foo4() {
    Selfie.expectSelfie("foo4").toMatchDisk();
  }

  @Test
  void foo5() {
    Selfie.expectSelfie("foo5").toMatchDisk();
  }

  @Test
  void foo6() {
    Selfie.expectSelfie("foo6").toMatchDisk();
  }

  @Test
  void foo7() {
    Selfie.expectSelfie("foo7").toMatchDisk();
  }

  @Test
  void foo8() {
    Selfie.expectSelfie("foo8").toMatchDisk();
  }

  @Test
  void foo9() {
    Selfie.expectSelfie("foo9").toMatchDisk();
  }

  @Test
  void foo10() {
    Selfie.expectSelfie("foo10").toMatchDisk();
  }
}

Running this test file in IntelliJ 2024.3 produces this ReproduceSelfieBugTest.ss file:

╔═ foo ═╗
foo
╔═ foo1 ═╗
foo1
╔═ foo2 ═╗
foo2
╔═ foo3 ═╗
foo3
╔═ foo4 ═╗
foo4
╔═ foo5 ═╗
foo5
╔═ foo6 ═╗
foo6
╔═ foo7 ═╗
foo7
╔═ foo8 ═╗
foo8
╔═ foo9 ═╗
foo9
╔═ test ═╗
0
╔═ test1 ═╗
1
╔═ test2 ═╗
2
╔═ test3 ═╗
3
╔═ test4 ═╗
4
╔═ test5 ═╗
5
╔═ test6 ═╗
6
╔═ test7 ═╗
7
╔═ test8 ═╗
8
╔═ test9 ═╗
9
╔═ testFoo ═╗
testFoo
╔═ testFoo1 ═╗
testFoo1
╔═ testFoo2 ═╗
testFoo2
╔═ testFoo3 ═╗
testFoo3
╔═ testFoo4 ═╗
testFoo4
╔═ testFoo5 ═╗
testFoo5
╔═ testFoo6 ═╗
testFoo6
╔═ testFoo7 ═╗
testFoo7
╔═ testFoo8 ═╗
testFoo8
╔═ testFoo9 ═╗
testFoo9
╔═ [end of file] ═╗

You will notice the snapshots for these tests are missing: foo10(), test10(), testFoo10, i.e. all tests ending with 10.

Additional information:
If you remove ALL tests except test(), test1() and test10() then the snapshot for test10() is correctly saved to disk.
After that, if test2() is added back and after re-running the test file, the snapshot for test10() is missing again. Then, after removing test2() once more and re-running the test file, the snapshot for test10() is STILL missing until the test file is run one more time.

主要语言
Kotlin
星标
101
派生
18
平均合并
6 天 11 小时
30 天内合并 PR
5

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

diffplug/selfie 的其他 Issue

查看 diffplug/selfie 的全部 Issue

相似的 Issue

更多 Kotlin Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。