Software testing a pdf is created correctly
-
I have written a REST application in laravel. It accepts a Json payload and creates a formatted pdf using this data. Is it possible to write a test that checks the pdf has been generated correctly? Edit: Ideally I'd like to know the pdf is not corrupted, ie. Will open in a pdf reader. Also it would be good to somehow check the content of the pdf. For example... does it contain the customers name? Thanks.
-
Answer:
Yes this is possible, given that the same JSON input always generates the same PDF. You wouldn't really check the PDF file. PDF is a complex format, based on PostScript and some dark magic. What you can do is generate a “sample” PDF once, then write a unit test that uses the same input data to generate a PDF file, then compare this to your sample. This would look something like (just some example code): $myPdf = $pdfGenerator->generatePdf(); $samplePdf = file_get_contents('/some/example/file.pdf'); // with PHPunit $this->assertEquals(0, strcmp($myPdf, $samplePdf)); That's a bit dirty, but it does the job … if something in your PDF or JSON implementation changes, the unit test will make you aware of it. It is important, however, that your PDF generator does not insert any “dynamic” data, such as date stamps. In that case, the PDF files could obviously never be identical.
Bowett at Stack Overflow Visit the source
Related Q & A:
- How To Get Job In Software Testing?Best solution by Yahoo! Answers
- How do I convert a PDF file to PDF/A in Delphi?Best solution by softwarerecs.stackexchange.com
- Software Testing Certifications?Best solution by astqb.org
- Which is the best software testing institute in Bangalore?Best solution by Yahoo! Answers
- How to find a career in Software Testing?Best solution by indeed.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.