简体   繁体   中英

How to write test cases for ProcessBuilder

In past, I've written JUnit test cases for API, Services, functions.

1st time I'm working on some command line utility that will be run using Java ProcessBuilder .I'm confused how I'll write test cases for that.

For example, I'm working on ghost script to break PDF in multiple tiff files.

So How can I write test cases for this case?

It depends on what are you going to test. For unit tests you need simple abstraction level over the API that you are going to use: test your own logic and verify that API was called via mocks (eg Mockito).

In integration tests you test your code as a whole and then verify the outcome. In your case you could pass some known PDF and then check the existence and size of the TIFF files produced by your script.

  1. Begin with a known PDF file.

  2. Break it down to tiff files and make sure they are all correct.

  3. Store all these files in a safe place, accessible to your unit test.

  4. Your unit test does the following:

    1. Invoke the script using Java ProcessBuilder. Let it read the known good PDF file and generate tiff files in a temporary directory.

    2. Compare each generated tiff file with the known good ones.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM