UnitTest module: where is my error message

0
I installed UnitTest module and created the simplest unit test script. This is an empty microflow which invariably returns string 'I failed'. Based on the documentation for the module, such unit test script should always fail and the returned message is treated as the error message. What I see is that my unit test fails indeed, but my error message is nowhere to be seen. What am I doing wrong?
asked
2 answers
1

Hi Miroslav,

    I am able to replicate what you are seeing: Running a unit test with a string as the return type returns success for an empty string and failure for a non-empty string.  However the 'result message' field is not populated with the string that is returned.  I have opened up the Java code, specifically the TestManager.java file, and it appears that the module is not set up to set the string as the error message if the string is non-empty.  It simply checks if the string is '' and if so, the result is true and the return message is set to 'Microflow completed successfully.'  The return message on a failure case only if an exception is returned or the return type is not correct.

I am unsure if this was the intended behavior of the module, but I agree with your intuition that it should return that string as the return message.  Changing this would involve editing the Java code or putting in an issue on the Git Hub

When I have used this, I have generally used the boolean return and have thrown exceptions if things didn't work.  That has gone fine for me as the module does log exceptions as you would expect.

 

  For those interested, the relevant block of code is in the runMicroflowTest method in the TestManager.Java.  Specifically this part:

		try {
			Object resultObject = Core.execute(mfContext, mf, emptyArguments);
			
			start = System.currentTimeMillis() - start;
			boolean res = 	resultObject == null || Boolean.TRUE.equals(resultObject) || "".equals(resultObject);
				
			test.setResult(res ? UnitTestResult._3_Success : UnitTestResult._2_Failed);
			
			if (res) {
				test.setResultMessage("Microflow completed successfully");
			}
			
			return res;
		}

 

answered
0

Rob, thank you for the insight. I assumed that the sentence in module documentation "For string results, a non empty string is interpreted as error message." assumes that my simple unit test will deliver the error message in the test result window.

I changed my basic unit test, and now it works as I wanted.

answered