Scala, Specs2, Mockito and null return values -
I am trying to test some scala codes using scans2 and mokoto. I am relatively new to all, and difficulty with fake returning methods.
In the following (written with some name changes)
"The process of my component" should be "{" Pass the parser in new module "{ Val file = mock [file] myComponent.process (file) There was a (moppress) .PRSE (file)} "mutate parse result for translator" module {val file = mock [file] val myType1 = mock [MyType1] MockParser.parse (file) Returns (myType1) myComponent.process (file) There was one (mock translator). Translestate (myType1)}} Unless I am in SUT If I add a call, then "Passer's pass file" works, and then dies because the mockparser.parse method returned an empty, which can not take the translator code. Similarly, as long as I do not try to use the translation result in SUT, "Pass Pars Results for Transcription" passes.
The actual code for both These methods can never return to the null, but I do not know How to tell Moc that kito will return usable results to make expectations.
I can certainly work on this by putting a redundant check in the SUT, but I do not want to, because I am making sure that never change and in return options Using none and some . Points for a good Scala / Specs 2 / Mokto tutorial will be amazing, as a simple example of how a line such as
should be changed there (MockPerser ). PRSE (File) allows it to do something like this
Chink about trying to understand it, I changed the line Tried
There was one (MockParser) .Raris (file) myResult gives value to my roustlet which I want to type This returns me a compilation error because I hope to find a mail result instead of my return. If it matters, then I am using Scala 2.9.0.
If you have not seen it, then you can see the specs2 documentation.
Edit after donation: In your code, there was a misunderstanding The way you do it in your other example is good and you should do the same in the first test: val file = fake [file] val myType1 = mock [MyType1] mockParser .PREC (file) returns (some (MyType 1)) myComponent.process (file) There was a (MACPRESSER). PRSE (file) The idea of unit testing with ridicule is always the same: tell how your workings work (press), execute, verify, verify.
You should answer this question, now a personalized advice:
Most of the time, if you want some algorithmic behavior (stop at first success, process a list in reverse order) To verify, you should not check the expectation in your unit test.
In your example, "translate things" to the process method, thus your unit tests should focus on it: to be fake of your parsers and translators, Stub and check the outcome of the whole process. It is a less good grain but the goal of a unit test is to not examine every step of a method. If you want to change the implementation, you do not need to modify a set of unit tests that verify each line of the method.
Comments
Post a Comment