Obiectivele proiectului .. 3 Tipuri de teste . 3 Unit Testing ... 4 Integration Testing . 5 System Testing 7 Concluzii .. 8
Obiectivele proiectului Proiectul este conceput pentru a ajuta dezvoltatorii de aplicatii pentru robotul roboRIO. Aplicatia simuleaza datele procesate de robot astfel se pot dezvolta si testa aplicatii de procesare a imaginilor WPILib fara a fi nevoie de un robot. Pentru a demonstra functionalitatea librariei am creat un proiect de test care detecteaza bilele rosii si albastre dintr-o imagine. . Tipuri de teste: Pentru acest proiect am ales sa fac urmatoarele tipuri de teste: -Unit testing -Integration testing -System testing Clasa testata: public class ImageProcessor { private IBallPipeline pipeline; private INetworkTableWriter networkTableWriter; private ExecutorService executor = Executors.newSingleThreadExecutor(); private Mat outputImage = new Mat(); private Future<?> processAsyncFuture; /** - ImageProcessor requires a pipeline to process and a network table writer to write - results to. - @param pipeline The pipeline to process - @param networkTableWriter A network table writer to send results to - / public ImageProcessor(IBallPipeline pipeline, INetworkTableWriter networkTableWriter) { if (pipeline == null) { throw new IllegalArgumentException(); } this.pipeline = pipeline; this.networkTableWriter = networkTableWriter; this.processAsyncFuture = null; } /** - Process an image asynchronously. Call awaitProcessCompletion to wait for completion. - You can only process one image at a time. 4 - @param inputImage The image to process - / public void processAsync(Mat inputImage) { if (processAsyncFuture != null) { throw new IllegalAccessError("Only one process can be awaited at a time."); } // Hold on the the future...use the awaiter to wait for completion processAsyncFuture = executor.submit(() -> { // Apply the pipeline to the image. pipeline.process(inputImage); // Update network table networkTableWriter.write(); return null; }); } - metoda pe care am testat-o este functia processAsync care face 2 lucruri: apeleaza pipelineul de lucru si scrie in tabela de network. Unit Testing: - am folosit frameworkul Mockito pentru a mockui interfetele de pipeline si networktabelwriter - cu acest tip de test doresc sa verific ca se apeleaza metodele de process si write din functia processAsync import org.junit.*; import org.opencv.core.*; import static org.mockito.Mockito.*; public class ImageProcessorUnitTest { // This must be done in order to call opencv classes static { System.loadLibrary("opencv_java310"); } @Test public void itShouldProcessMyPipeline() { IBallPipeline pipelineMock = mock(IBallPipeline.class); INetworkTableWriter networkTableWriterMock = mock(INetworkTableWriter.class); ImageProcessor imageProcessor = new ImageProcessor(pipelineMock, networkTableWriterMock); 5 Mat emptyImage = new Mat(); // Act imageProcessor.processAsync(emptyImage); imageProcessor.awaitProcessCompletion(); //Assert verify(pipelineMock, times(1)).process(emptyImage); }
Plătește în siguranță cu cardul și beneficiezi de garanția 200% din partea Proiecte.ro.
Simplu și rapid în doar 2 pași: completezi datele tale și plătești.