I lean Spring Boot with Book.(copy and paste from book to editor)
There is I can't understand and not working code.
Could you teach me How can I fix and what should I learn?
@Test
//@Sql("file:C:/Users/<username>/Desktop/springsample/src/test/resources/testdata.sql") //This is work!
@Sql("/testdata.sql") // This is not work.
public void countTest2(){
assertEquals(dao.count(), 3);
}
Please check above code, @Sql("/testdata.sql") is not work.
Junit result is like that.
Caused by: java.io.FileNotFoundException: class path resource [testdata.sql] cannot be opened because it does not exist
So I wrote code that is comment out now. It worked.
I think that have to rewrite @Sql argument. But I don't know how to do that.
Could you teach me how to rewrite code?
Is this problem come from lack of my Maven directory rule?
Appendix
Directory tree is below.
tree /F C:\Users\<username>\Desktop\springsample\src\test
C:\USERS\<username>\DESKTOP\SPRINGSAMPLE\SRC\TEST
├─java
│ └─com
│ └─example
│ └─springsample
│ DemoApplicationTests.java
│ UserDaoTest.java //Test code in this file.
│
└─resources
testdata.sql
Thank you for reading.
Additional Info
I read reference,then tried below setting is work. In this case, need to put the .sql file same directory as Test class file. I think can assignment specified location. But I can't.
@Sql("testdata.sql")
■Directory Tree
C:\USERS\<username>\DESKTOP\SPRINGSAMPLE\SRC\TEST
├─java
│ └─com
│ └─example
│ └─springsample
│ DemoApplicationTests.java
│ UserDaoTest.java //Test code in this file.
│ testdata.sql
└─resources
└─com
└─example
└─springsample