avatar
junit question# Java - 爪哇娇娃
c*t
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.
avatar
m*t
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.

avatar
c*t
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.

avatar
A*o
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

avatar
m*t
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

avatar
c*t
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". ;-)

avatar
m*t
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.

avatar
c*t
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.

avatar
A*o
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.
avatar
c*t
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.

avatar
g*g
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

avatar
c*t
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.

avatar
g*g
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.

avatar
c*t
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.

avatar
m*t
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.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。