I have an object with a message that gets a stream and print into it.
My problem is testing that I am printing the right string.
I could do it with output redirection and a testing script, but I would rather do it using the assert of the TestCase class, if that is possible.
Thanks for any help :)
Asked
Active
Viewed 259 times
1

Sam DeHaan
- 10,246
- 2
- 40
- 48

Mugen
- 8,301
- 10
- 62
- 140
-
Some sample code would help... – Sean DeNigris Apr 03 '12 at 16:19
-
I have a calss A, and in it a message called (printOn:) that is printing a string describing the A object into a given stream. – Mugen Apr 03 '12 at 21:03
-
You can create a stream using `WriteStream on: String new` and send `contents` to it for retriving its contents. – Alex Jasmin Apr 03 '12 at 21:33
-
@AlexandreJasmin: Might be worth creating an answer from your comment so Mugen can mark it as accepted. – Amos M. Carpenter Apr 04 '12 at 03:25
1 Answers
2
You can create a stream that writes to an in-memory string with WriteStream on: String new
.
Send contents
to that stream for retrieving the string contents.
That should help you test your code.

Alex Jasmin
- 39,094
- 7
- 77
- 67