How to find out which setup failed in Assert of `VerifyAll`? - moq

I am writing the unit test for a method. I have properly configured all the setups. While debugging unit test it works and returns values as expected. But in assertion it still throws false.
Therefore, I am not able to understand why does VerifyAll throws false all the time? How to find out which setup failed the VerifyAll assert?

VerifyAll verifies that all your Setups were called. It sounds like you have a Setup that is not relevant to your test, hence your are getting the expected output, yet the VerifyAll fails because that Setup was never called.
When VerifyAll fails you will get an exception, and the reason is given there. For example, if I create an unused Setup in a test I get:
Moq.MockVerificationException : The following setups were not matched:
IMyClass m => m.MyMethod()

Related

Managing external code errors

I am trying to run an external code in OpenMDAO 2 that outputs some minor error messages as part of it's run process in windows shell. These error messages does not affect the results of the code and the code runs itself normally. However OpenMDAO raises a fault and stops whenever it detects these error messages. Is it possible for OpenMDAO to ignore such situation and continue running the analysis? I have tried setting fail_hard option to false, but it doesn't seem to change the behavior except that OpenMDAO raises analysis error instead of run-time error.
We can implement a feature to let you specify allowable return codes.. as long as you can enumerate which return codes are not errors, I think this will solve your problem?

i have phpunit test that directly interect with database and when assert fail it stop test and don't pass to the nest assert

I have PHPUnit test that directly interacts with database and when the assert fails, it throws an error and then stops the test and doesn't execute the next assert.
What I need is that when an assert fails, it should pass to the next assert and throw an error at the end of the test.
My biggest issue is because I am interacting with database, when I make Insert, Update, GetAll, GetbyID at the end of test I always make Delete.
I know there other ways of testing without interacting with the database but I was asked to make a test that interacts with the database, so what I need something like (SOFT ASSERT-TRY CATCH) in PHPUnit.
So please anyone that has an answer help me.
If you have a configuration file:
<phpunit
stopOnError="false"
stopOnFailure="false">
Set those two attributes to false, or if running off the command line use
--stop-on-error
--stop-on-failure

web flow don't recognize domainClass.list()

When calling this function in a webflow step:
domainClass.findAllByIdInList(givenList)
I get a null pointer exception. When executing:
domainClass.list()
I get nothing. I tried to pass this code to the server and get the same exception. Why is this happening?

Equivalent of PHP Die(): how to stop function's execution on server

I am building a Meteor application with some custom authentication in addition to the built-in accounts MDG package.
I want to have a function I call at the front of Meteor methods to verify authentication. If authentication fails, I would like to do the equivalent of PHP's die() function - return a message and stop execution.
I could always do something like this: if(!checkAuth()) return "Not Authenticated", however it would be nice if I could just do checkAuth() and that function takes care of stopping execution if correct permissions are not met.
Is there a way to do this?
The easy way is to throw a new Meteor.Error. If not caught it will stop the currently running function, and if it is thrown from a method or a subscription it will appear on the client-side.
function checkAuth(user) {
if(!isAuthenticated(user)) {
throw new Meteor.Error('not-authenticated', 'Users need to be authenticated to do foo')
}
}
The above thrown error server-side will appear on the client with the reason and the details. It allows you to do custom error handling tailored to whatever is happening. If any other kind of error is thrown, it will appear as "500 Internal server error".
Note that this mechanism is similar to check. You could even use a custom Match pattern :
check(user, MyPatterns.authenticatedUser)

How to stop running tests if a specific test fails?

I know there is an option in PHPUnit to stop-on-failure but I don't want it to stop when any test fails, just when this specific test fails.
For example, in my setUp I connect to a DB, and in the first test I check if it connected to the correct DB. If that fails, I can't run the rest of the tests.
Use the #depends feature of PHP.
If a test depends on another, it will only be executed if that other test succeeded. Otherwise it will be skipped. This allows you to pinpoint problems better.
Usage: Add a PHPDOC block at the top of the test function that should only be executed when the other test is successful, and add a line #depends testConnectToDb.
See http://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.depends and http://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.test-dependencies for some more details.

Resources