0

I have a large piece of Java software that I am looking to add tests to for a new module. The new module involves running external applications and handling the results. The external applications are not something I can modify. In order to get results, these external applications need to be able to access and modify 2+ remote machines. Once they make those modifications, that machine is no longer in a valid state for more testing. My current application already includes JUnit tests, so it would be nice if I could write the new tests in JUnit as well.

My question: Is there a know technique for this use case? I know I could hack together some kind of solution using Vagrant, where machines are started up and torn down in the setup and teardown blocks of JUnit, but that seems like it could be hard to maintain, would require the tests to be run serially, and would be very, very slow.

EDIT: Removed the word "unit" because it was significantly sidetracking the question.

Alex N.
  • 654
  • 8
  • 21
  • 2
    When a test involves multiple virtual machines it is not a unit test anymore, but an integration test or a system test. – Thorbjørn Ravn Andersen Mar 20 '17 at 17:33
  • 1
    I would make it that you can start up, test, shutdown and reset the tests as many times as you need. It's not really a unit test any more but you can still use JUnit to run it. I would also make it that the test can be start up and shutdown quickly e.g. seconds, or milli-seconds. For our own systems I try to make it that remote tests can be reset in under a second. – Peter Lawrey Mar 20 '17 at 17:33
  • @ThorbjørnRavnAndersen I don't think there is really an common definition that separates unit and integration testing. In this case, I call it unit testing because because each test I want to create will test a small, distinct piece of the system. However, if you have a good solution in the area of integration testing instead of unit testing, I would love to hear it. – Alex N. Mar 20 '17 at 17:38
  • *"Once they make those modifications, that machine is no longer in a valid state for more testing. My current application already includes JUnit tests, so it would be nice if I could write the new tests in JUnit as well."* create a *test environment* where those servers are on (a) *VirtualMashine(s)* which you can reset so a saves state during setup of your *application tests* done via JUnit. – Timothy Truckle Mar 20 '17 at 17:39
  • *"I don't think there is really an common definition that separates unit and integration testing."* You're wrong: http://artofunittesting.com/definition-of-a-unit-test/ https://martinfowler.com/bliki/UnitTest.html https://www.techopedia.com/definition/9847/unit-test – Timothy Truckle Mar 20 '17 at 17:42
  • @TimothyTruckle According the the first link, I'm not doing unit testing. According to the second link, definitions vary but I meet most of his criteria. And according to the third one, I am doing unit testing. I'll change the question to reflect the confusion over what I want to do. – Alex N. Mar 20 '17 at 17:55
  • @AlexN. The important point is: UnitTests test units of code *in isolation*. This means isolation from *external systems* as well as from *other units*. Anything else is *integration test done with JUnit*. – Timothy Truckle Mar 20 '17 at 20:23

0 Answers0