Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jarから実行するとkgpのテスト実行ができなくなる #6

Closed
hrtwt opened this issue Feb 24, 2022 · 7 comments
Closed

jarから実行するとkgpのテスト実行ができなくなる #6

hrtwt opened this issue Feb 24, 2022 · 7 comments
Assignees
Labels
backend bug Something isn't working

Comments

@hrtwt
Copy link
Contributor

hrtwt commented Feb 24, 2022

問題

java -jar fldomo.jarで実行したバックエンドに対して,

curl -X POST -H "Content-Type: application/json" --data '{"src": "package example;\n\npublic class CloseToZero {\n\n  /* Increase or reduce the given value to be close to zero. */\n  public static int run(int n) {\n    if (n == 0) {\n      n++; // a bug here. zero should be zero\n    } else if (n > 0) {\n      n--;\n    } else {\n      n++;\n    }\n    return n;\n  }\n\n}",  "test": "package example;\n\nimport static org.junit.Assert.assertEquals;\nimport org.junit.Test;\n\npublic class CloseToZeroTest {\n  @Test\n  public void test01() {\n    assertEquals(4, CloseToZero.run(5));\n  }\n\n  @Test\n  public void test02() {\n    assertEquals(0, CloseToZero.run(0));\n  }\n\n  @Test\n  public void test03() {\n    assertEquals(-4, CloseToZero.run(-5));\n  }\n\n}"}' http://localhost:8080/api/fl/all

すると,レスポンスのFL結果が空になる.

{"DStar":{"suspiciousnesses":{}},"Jaccard":{"suspiciousnesses":{}},"Zolter":{"suspiciousnesses":{}},"Ample":{"suspiciousnesses":{}},"Ochiai":{"suspiciousnesses":{}},"Tarantula":{"suspiciousnesses":{}}}

expected behavior

./gradlew bootrunで実行した場合

{"DStar":{"suspiciousnesses":{"7":0.5,"8":"Infinity","14":0.5}},"Jaccard":{"suspiciousnesses":{"7":0.3333333333333333,"8":1.0,"14":0.3333333333333333}},"Zolter":{"suspiciousnesses":{"7":0.3333333333333333,"8":1.0,"14":0.3333333333333333}},"Ample":{"suspiciousnesses":{"8":1.0,"9":1.0,"10":0.5,"12":0.5}},"Ochiai":{"suspiciousnesses":{"7":0.5773502691896258,"8":1.0,"14":0.5773502691896258}},"Tarantula":{"suspiciousnesses":{"7":0.5,"8":1.0,"14":0.5}}}
@hrtwt hrtwt self-assigned this Feb 24, 2022
@hrtwt hrtwt added backend bug Something isn't working labels Feb 24, 2022
@hrtwt
Copy link
Contributor Author

hrtwt commented Feb 24, 2022

原因:JUnitがテストメソッドを発見していない

kgpがテスト失敗の理由を持っているので,確認すると initializationError No runnable methods
これはJUnitのエラーメッセージで,@Testを発見できなかったことが原因.
つまり,kgp(JUnit)的には与えたテストクラス内にテストメソッドが1つもないように見えている.

@hrtwt
Copy link
Contributor Author

hrtwt commented Feb 24, 2022

原因:@Testの型定義がない

java.lang.TypeNotPresentException: Type org.junit.Test not present

image

https://github.com/openjdk/jdk/blob/51f3427e9bb4a3924a8178338316b9ea30304182/src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java#L237-L250

@hrtwt
Copy link
Contributor Author

hrtwt commented Feb 24, 2022

与えられたテストクラス内にテストメソッドが含まれていなかった場合の適切な挙動は #7 で検討

@hrtwt
Copy link
Contributor Author

hrtwt commented Feb 24, 2022

試したこと

build.gradleruntimeOnly 'junit:junit:4.13.2'を追記
jarにjunit-4.13.2.jarは入ったが依然ダメ.

@hrtwt
Copy link
Contributor Author

hrtwt commented Feb 24, 2022

workaround

./gradlew bootRun で起動
Jar起動をしない

hrtwt added a commit that referenced this issue Feb 24, 2022
@hrtwt
Copy link
Contributor Author

hrtwt commented Feb 25, 2022

spring-projects/spring-boot#1828 (comment)
shadowJarを使えば動くらしい

@hrtwt
Copy link
Contributor Author

hrtwt commented Mar 1, 2022

shadowJarで解決
2177dc3

@hrtwt hrtwt closed this as completed Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant