Monday, 15 September 2014

unit testing - How do I test code with serious side-effect? -


Uniteite is important during development, but testing some code is not easy.

If I have some code:

  class filesystem (def): def def (self, fs): os.system ("Mkfs.ext4% s"% Fs) #assert (self.size (fs) == 0)   

I can not delete a file system for a test.

For this situation, I can make a file-based drive on UNIX for testing.

But, if it is an API class:

  class blog (): Def post (auto, text): blog.library.post (self.access_key, text )   

I do not want to post a blog article for testing.

What should I do?

For unit tests:

Make your class directly blog. Library should not interact with , but through some intermediate layer you are injected as the blog class dependencies, you make a duplicate for this and claim The required method was implemented with the required parameters.

For Functional / Integration Trials:

You establish the Dummy Blog Engine and the actual post. Then check that the post actually appears with the http request on the page.

No comments:

Post a Comment