javatestingjunitexternal-tools

multistep testing with Junit


I'm working on a simple compiler for class that takes input from a higher-level language and produces quasi-assembly code that runs on an emulator. I'm trying to set up test cases for the program that compare the expected output of the emulator with the actual output, but I've been having issues since running code on the emulator requires two stages of processing. In stage one I run my compiler and in stage two I run the output code in the emulator (which I run as an external tool in Eclipse by clicking this button: enter image description here. I've gotten to the point where I can test the output of the compiler (i.e. the assembly language) in JUnit, but I'm not sure how to take that final step to run the emulator from within JUnit.


Solution

  • You could programatically run the emulator using Runtime.exec() from within the body of your test method.

    But normally you wouldn't want to resort to something like this. Unit tests should try to test one thing in isolation - your compiler in this case. It sounds like your test cases should consist of the HLL input and expected assembly output; leave the emulator out of it.