Re: test data location question
use getResource to get the URL of the resource and then parsethe URL to find the file path On 07/05/2009, Pete Siemsen wrote: > That seems reasonable, but I still don't understand how to make it work. > > The program I'm trying to test is like a compiler. It reads source > files that can contain "include" statements. When it parses such a > statement, the program needs to open the include file and start > parsing statements in the include file. > > If I use getResourceAsStream, what can I do when I encounter the > "include" statement? How can I open the include file if I can't > specify the path that leads to the include file, relative to the > initial input stream? > > As I wrote, the program is working just fine. It reads a file name > from the command line. My question is how to test it within the maven > framework, without specifying absolute test file names. > > Cheers, > -- Pete > > > On May 5, 2009, at 3:55 PM, Jeff MAURY wrote: > >> You should store your files under src/test/resources and load your >> files using getResourceAsStream >> >> Regards >> Jeff MAURY >> >> On Tue, May 5, 2009 at 11:37 PM, Pete Siemsen >> wrote: >> >>> This is a basic question about how to run Java unit tests that >>> require file names. >>> >>> I use maven to develop a program that reads input file names from >>> the command line. It's working fine, but now I want to share the >>> code with someone else. The test programs live in ../src/test/ >>> java, and the test data lives in ../src/test/data. Until now, I've >>> used fully-qualified paths hard-coded into my test programs, like / >>> Users/siemsen/TranslateCIM/src/test/data/cim/ >>> testArrayTypeOnNonArray/testATONA.mof. >>> >>> If I tar up my development directory and give it to someone else, >>> the fully-qualified paths obviously don't work. I want to make the >>> paths relative somehow. The program reads an input file that may >>> contain "include" statements that cause the program to open other >>> files relative to the first input file. It seems to my newbie eyes >>> that using resources and getResourceAsStream won't allow me to open >>> subfiles. >>> >>> What I think I want is a runtime environment variable or something >>> that tells me the path to the maven development directory. >>> >>> Any suggestion would be appreciated. >>> >>> -- Pete > > - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: test data location question
Your compiler should be aware of the resource it is working on and not only of the input stream. This is a common case when dealing with embeded resource. Look at XML parsers for example. Regards Jeff MAURY On Fri, May 8, 2009 at 12:39 AM, Pete Siemsen wrote: > That seems reasonable, but I still don't understand how to make it work. > > The program I'm trying to test is like a compiler. It reads source files > that can contain "include" statements. When it parses such a statement, the > program needs to open the include file and start parsing statements in the > include file. > > If I use getResourceAsStream, what can I do when I encounter the "include" > statement? How can I open the include file if I can't specify the path that > leads to the include file, relative to the initial input stream? > > As I wrote, the program is working just fine. It reads a file name from > the command line. My question is how to test it within the maven framework, > without specifying absolute test file names. > > Cheers, > -- Pete > > > On May 5, 2009, at 3:55 PM, Jeff MAURY wrote: > > You should store your files under src/test/resources and load your files >> using getResourceAsStream >> >> Regards >> Jeff MAURY >> >> On Tue, May 5, 2009 at 11:37 PM, Pete Siemsen wrote: >> >> This is a basic question about how to run Java unit tests that require >>> file names. >>> >>> I use maven to develop a program that reads input file names from the >>> command line. It's working fine, but now I want to share the code with >>> someone else. The test programs live in ../src/test/java, and the test data >>> lives in ../src/test/data. Until now, I've used fully-qualified paths >>> hard-coded into my test programs, like >>> /Users/siemsen/TranslateCIM/src/test/data/cim/testArrayTypeOnNonArray/testATONA.mof. >>> >>> If I tar up my development directory and give it to someone else, the >>> fully-qualified paths obviously don't work. I want to make the paths >>> relative somehow. The program reads an input file that may contain >>> "include" statements that cause the program to open other files relative to >>> the first input file. It seems to my newbie eyes that using resources and >>> getResourceAsStream won't allow me to open subfiles. >>> >>> What I think I want is a runtime environment variable or something that >>> tells me the path to the maven development directory. >>> >>> Any suggestion would be appreciated. >>> >>> -- Pete >>> >> > -- La mélancolie c’est communiste Tout le monde y a droit de temps en temps La mélancolie n’est pas capitaliste C’est même gratuit pour les perdants La mélancolie c’est pacifiste On ne lui rentre jamais dedans La mélancolie oh tu sais ça existe Elle se prend même avec des gants La mélancolie c’est pour les syndicalistes Il faut juste sa carte de permanent Miossec (2006) http://www.jeffmaury.com http://riadiscuss.jeffmaury.com http://www.lastfm.fr/listen/user/jeffmaury/personal
Re: test data location question
That seems reasonable, but I still don't understand how to make it work. The program I'm trying to test is like a compiler. It reads source files that can contain "include" statements. When it parses such a statement, the program needs to open the include file and start parsing statements in the include file. If I use getResourceAsStream, what can I do when I encounter the "include" statement? How can I open the include file if I can't specify the path that leads to the include file, relative to the initial input stream? As I wrote, the program is working just fine. It reads a file name from the command line. My question is how to test it within the maven framework, without specifying absolute test file names. Cheers, -- Pete On May 5, 2009, at 3:55 PM, Jeff MAURY wrote: You should store your files under src/test/resources and load your files using getResourceAsStream Regards Jeff MAURY On Tue, May 5, 2009 at 11:37 PM, Pete Siemsen wrote: This is a basic question about how to run Java unit tests that require file names. I use maven to develop a program that reads input file names from the command line. It's working fine, but now I want to share the code with someone else. The test programs live in ../src/test/ java, and the test data lives in ../src/test/data. Until now, I've used fully-qualified paths hard-coded into my test programs, like / Users/siemsen/TranslateCIM/src/test/data/cim/ testArrayTypeOnNonArray/testATONA.mof. If I tar up my development directory and give it to someone else, the fully-qualified paths obviously don't work. I want to make the paths relative somehow. The program reads an input file that may contain "include" statements that cause the program to open other files relative to the first input file. It seems to my newbie eyes that using resources and getResourceAsStream won't allow me to open subfiles. What I think I want is a runtime environment variable or something that tells me the path to the maven development directory. Any suggestion would be appreciated. -- Pete
Re: test data location question
You should store your files under src/test/resources and load your files using getResourceAsStream Regards Jeff MAURY On Tue, May 5, 2009 at 11:37 PM, Pete Siemsen wrote: > This is a basic question about how to run Java unit tests that require file > names. > > I use maven to develop a program that reads an input file names from the > command line. It's working fine, but now I want to share the code with > someone else. The test programs live in ../src/test/java, and the test data > lives in ../src/test/data. Until now, I've used fully-qualified paths > hard-coded into my test programs, like > /Users/siemsen/TranslateCIM/src/test/data/cim/testArrayTypeOnNonArray/testATONA.mof. > > If I tar up my development directory and give it to someone else, the > fully-qualified paths obviously don't work. I want to make the paths > relative somehow. The program reads an input file that may contain > "include" statements that cause the program to open other files relative to > the first input file. It seems to my newbie eyes that using resources and > getResourceAsStream won't allow me to open subfiles. > > What I think I want is a runtime environment variable or something that > tells me the path to the maven development directory. > > Any suggestion would be appreciated. > > -- Pete > > > > > - > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > For additional commands, e-mail: users-h...@maven.apache.org > > -- La mélancolie c’est communiste Tout le monde y a droit de temps en temps La mélancolie n’est pas capitaliste C’est même gratuit pour les perdants La mélancolie c’est pacifiste On ne lui rentre jamais dedans La mélancolie oh tu sais ça existe Elle se prend même avec des gants La mélancolie c’est pour les syndicalistes Il faut juste sa carte de permanent Miossec (2006) http://www.jeffmaury.com http://riadiscuss.jeffmaury.com http://www.lastfm.fr/listen/user/jeffmaury/personal
test data location question
This is a basic question about how to run Java unit tests that require file names. I use maven to develop a program that reads an input file names from the command line. It's working fine, but now I want to share the code with someone else. The test programs live in ../src/test/java, and the test data lives in ../src/test/data. Until now, I've used fully- qualified paths hard-coded into my test programs, like /Users/siemsen/ TranslateCIM/src/test/data/cim/testArrayTypeOnNonArray/testATONA.mof. If I tar up my development directory and give it to someone else, the fully-qualified paths obviously don't work. I want to make the paths relative somehow. The program reads an input file that may contain "include" statements that cause the program to open other files relative to the first input file. It seems to my newbie eyes that using resources and getResourceAsStream won't allow me to open subfiles. What I think I want is a runtime environment variable or something that tells me the path to the maven development directory. Any suggestion would be appreciated. -- Pete - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org