c*****t 发帖数: 1879 | 1 So far all of my junit4 tests are on functions in public classes.
Anyway to test functions in classes of package scope without having
to change the class signature? thx. |
m******t 发帖数: 2416 | 2
One of the best practices, I believe, is keeping your
test case classes in the same package as the classes
being tested, for exactly the reason that you want to
be able to test package level stuff.
【在 c*****t 的大作中提到】 : So far all of my junit4 tests are on functions in public classes. : Anyway to test functions in classes of package scope without having : to change the class signature? thx.
|
c*****t 发帖数: 1879 | 3 That is a bomber :( My test cases could be as big if not bigger than
the actual code itself. Maybe I could try fiddling with class name
a bit.
thx
【在 m******t 的大作中提到】 : : One of the best practices, I believe, is keeping your : test case classes in the same package as the classes : being tested, for exactly the reason that you want to : be able to test package level stuff.
|
A**o 发帖数: 1550 | 4 normally there is a src folder for prod sources.
and there is a test folder for test sources...
for example: src/com/coco and test/src/com/coco
【在 c*****t 的大作中提到】 : That is a bomber :( My test cases could be as big if not bigger than : the actual code itself. Maybe I could try fiddling with class name : a bit. : thx
|
m******t 发帖数: 2416 | 5
"Same package" doesn't have to mean "same source
folder". ;-)
【在 c*****t 的大作中提到】 : That is a bomber :( My test cases could be as big if not bigger than : the actual code itself. Maybe I could try fiddling with class name : a bit. : thx
|
c*****t 发帖数: 1879 | 6 I see what you mean. Thanks :)
p.s. any simple approaches to test a function output (multiline) to a text
file
using junit? thx.
【在 m******t 的大作中提到】 : : "Same package" doesn't have to mean "same source : folder". ;-)
|
m******t 发帖数: 2416 | 7
Hmm... have a baseline(i.e. verified) version of that text file, and
compare it to the test output? Or if the function takes a Writer or
OutputStream, pass it a ByteArrayWriter, and compare the result
with the expected result.
【在 c*****t 的大作中提到】 : I see what you mean. Thanks :) : p.s. any simple approaches to test a function output (multiline) to a text : file : using junit? thx.
|
c*****t 发帖数: 1879 | 8 erh, I guess that I will just use shell script then. thx.
【在 m******t 的大作中提到】 : : Hmm... have a baseline(i.e. verified) version of that text file, and : compare it to the test output? Or if the function takes a Writer or : OutputStream, pass it a ByteArrayWriter, and compare the result : with the expected result.
|
A**o 发帖数: 1550 | 9 the other way is to refactor your function
so that it's easier to be tested, maybe without touch files,
if possible.
【在 c*****t 的大作中提到】 : erh, I guess that I will just use shell script then. thx.
|
c*****t 发帖数: 1879 | 10 I have to test outputs against standard outputs. My code is a
compiler-compiler (i.e. lex/yacc like).
Even worse, I might have to test the if the outputted java code
which in turn gets compiled produce the right outputs for given
inputs.
One of the reason why I needed to test is because a slight tweak
may not be apparent in correctness, and only through tests to
tell. A single generated piece of code itself can work in some
cases, but not all cases...
I am having a major headache :( ATM, I ca
【在 A**o 的大作中提到】 : the other way is to refactor your function : so that it's easier to be tested, maybe without touch files, : if possible.
|
|
|
g*****g 发帖数: 34805 | 11 junit is just a funtion you setup to compare 2 values.
It doesn't stop you from calling a commandline script
if you want to evaluate that way.
【在 c*****t 的大作中提到】 : I have to test outputs against standard outputs. My code is a : compiler-compiler (i.e. lex/yacc like). : Even worse, I might have to test the if the outputted java code : which in turn gets compiled produce the right outputs for given : inputs. : One of the reason why I needed to test is because a slight tweak : may not be apparent in correctness, and only through tests to : tell. A single generated piece of code itself can work in some : cases, but not all cases... : I am having a major headache :( ATM, I ca
|
c*****t 发帖数: 1879 | 12 It'd easier if that junit/testng can automatically read the output
of the code and compares the output from text file (like using
annotations to specify the comparison ouput location). Then I
could potentially do everything without using script. Sigh...
Right now in IDEA, i just need to hit run on the test folder and
everything is tested (the main reason why i use junit). Would be
painful that I have to find other ways.
【在 g*****g 的大作中提到】 : junit is just a funtion you setup to compare 2 values. : It doesn't stop you from calling a commandline script : if you want to evaluate that way.
|
g*****g 发帖数: 34805 | 13 It's easy to redirect output to a text file.
On windows, use something like,
yourProgram >result.txt
Your IDE probably can do the same thing.
Then it's up to you how you want to compare text.
【在 c*****t 的大作中提到】 : It'd easier if that junit/testng can automatically read the output : of the code and compares the output from text file (like using : annotations to specify the comparison ouput location). Then I : could potentially do everything without using script. Sigh... : Right now in IDEA, i just need to hit run on the test folder and : everything is tested (the main reason why i use junit). Would be : painful that I have to find other ways.
|
c*****t 发帖数: 1879 | 14 That's not the point... The point was that with like a dozen such
tests, how to do it quickly without switching windows around and
spend time to build a script. It is also a major headache to track
output files.
【在 g*****g 的大作中提到】 : It's easy to redirect output to a text file. : On windows, use something like, : yourProgram >result.txt : Your IDE probably can do the same thing. : Then it's up to you how you want to compare text.
|
m******t 发帖数: 2416 | 15
Does IDEA let you configure it to redirect stdout to
files for test runs? I know Eclipse does. You can then
write a @AfterTest method that does the comparing.
【在 c*****t 的大作中提到】 : It'd easier if that junit/testng can automatically read the output : of the code and compares the output from text file (like using : annotations to specify the comparison ouput location). Then I : could potentially do everything without using script. Sigh... : Right now in IDEA, i just need to hit run on the test folder and : everything is tested (the main reason why i use junit). Would be : painful that I have to find other ways.
|