由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - junit question
相关主题
今天被问到eclipse pluginany tools for ...
有多少人对annotation这个东西不满,请举手!!使用eclipse方法对第三方库建立Wrapper的小技巧。
What's going on with Spring IDE's website?how to refactor overlayered applications?
大家都是什么时候model classes?Any body uses wicket framework for web development?
请教:怎么把synchronize的method改成用thread 但thread safe呢?Tabs defined by user can't be saved
Re: cannot make JSSE work, faint!请问JSP/SERVLET和MYSQL如何实现照片上载和调用
请教Programming booksServlet的IO吞吐瓶颈在哪里?为什么测下来只有3M bytes 左右?
请问java的ideInputStream.read() 被block的问题(陷入无限等待)
相关话题的讨论汇总
话题: test话题: junit话题: output话题: classes话题: text
进入Java版参与讨论
1 (共1页)
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.

相关主题
Re: cannot make JSSE work, faint!any tools for ...
请教Programming books使用eclipse方法对第三方库建立Wrapper的小技巧。
请问java的idehow to refactor overlayered applications?
进入Java版参与讨论
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.

1 (共1页)
进入Java版参与讨论
相关主题
InputStream.read() 被block的问题(陷入无限等待)请教:怎么把synchronize的method改成用thread 但thread safe呢?
java可以直接去读txt file里指定的一行吗?Re: cannot make JSSE work, faint!
annotation question请教Programming books
spring Annotation based configuration请问java的ide
今天被问到eclipse pluginany tools for ...
有多少人对annotation这个东西不满,请举手!!使用eclipse方法对第三方库建立Wrapper的小技巧。
What's going on with Spring IDE's website?how to refactor overlayered applications?
大家都是什么时候model classes?Any body uses wicket framework for web development?
相关话题的讨论汇总
话题: test话题: junit话题: output话题: classes话题: text