assert

Can I write a test without any assert in it ?

Hi, I'd like to know if it is "ok" to write a test without any "assert" in it. So the test would fail only when an exception / error has occured. Eg: like a test which has a simple select query, to ensure that the database configuration is right. So when I change some db-configuration, I re-run this test and check if the configuration ...

"'assert’ was not declared in this scope" in MySQL++

I'm compiling a project in XCode where MySQL++ in included and linked to. For some reason, I keep getting the following compiler error: 'assert’ was not declared in this scope originating from cpool.h, a header file that's part of MySQL++. Does anyone know why this is being triggered? EDIT: For reference, MySQL++ was installed via M...

[NUnit+Moq] Guidelines for using Assert versus Verify

I'm new to unit testing, and I'm learning how to use NUnit and Moq. NUnit provides Assert syntax for testing conditions in my unit tests, while Moq provides some Verify functions. To some extent these seem to provide the same functionality. How do I know when it's more appropriate to use Assert or Verify? Maybe Assert is better for con...

Appending facts into an existing prolog file.

Hi, I'm having trouble inserting facts into an existing prolog file, without overwriting the original contents. Suppose I have a file test.pl: :- dynamic born/2. born(john,london). born(tim,manchester). If I load this in prolog, and I assert more facts: | ?- assert(born(laura,kent)). yes I'm aware I can save this by doing: |?...

one line assert to test if STL container is sorted

Is there a way to write a one line condition that would return true if STL container is sorted? The container in question is std::vector I intend to use it in an assert ...

What are the advantages or difference in “assert False” and “self.assertFalse”

Hello, I am wrting test's and I have heard some people saying to use self.assertFalse rather than assert False. Why is this and are there any advantages to be had? Thanks ...

assert vs. JUnit Assertions

Today I saw a JUnit test case with a java assertion instead of the JUnit assertions - What are the best practices in this respect? ...

why assert_equal() in Ruby on Rails sometimes seem to compare by Identity and sometimes by value?

it was very weird that yesterday, I was do an integration test in Rails and assert_equal array_of_obj1, array_of_obj2 # obj1 from db, obj2 created in test and it failed. The values shown inside the array and objects were identical. If I change the test to assert array_of_obj1 == array_of_obj2 Then it will pass. But today, th...

Test assertions for tuples with floats

I have a function that returns a tuple that, among others, contains a float value. Usually I use assertAlmostEquals to compare those, but this does not work with tuples. Also, the tuple contains other data-types as well. Currently I am asserting every element of the tuple individually, but that gets too much for a list of such tuples. Is...

Debug.Assert-s use the same error message. Should I promote it to a static variable?

I love Asserts and code readability but not code duplication, and in several places I use a Debug.Assert which checks for the same condition like so: Debug.Assert(kosherBaconList.SelectedIndex != -1, "An error message along the lines - you should not ever be able to click on edit button without selecting a kosher bacon first."); This ...

Is it good practice to use assert() in class mutators?

For example: void Date::month(unsigned int inMonth) { assert(inMonth <= 12); _month = inMonth; } If this is not good practice, what is the correct way to go about this? ...

How can I display more info in an error message when using NUnit Assert in a loop?

Consider the following code: [Test] public void WidgetTest() { foreach (Widget widget in widgets) { Assert.AreEqual(0, widget.SomeValue); } } If one of the asserts fails, I will get a very unhelpful error message like the one below: 1) Test Failure : WidgetTest.TestSomeValue Expected: 0 But was: 1 at WidgetT...

php numbers: assert( 1.0 < 2.0 )

How can this <?php assert( 1.0 < 2.0 ); ?> result in Warning: assert() [function.assert]: Assertion failed in C:\Program Files (x86)\wamp\www\test.php on line 2 Edit: depending on the file I put this code in, 1.0 < 2.0 evaluates to false or true. ...

python assert with and without parenthesis

Here are four simple invocations of assert: >>> assert 1==2 Traceback (most recent call last): File "<stdin>", line 1, in ? AssertionError >>> assert 1==2, "hi" Traceback (most recent call last): File "<stdin>", line 1, in ? AssertionError: hi >>> assert(1==2) Traceback (most recent call last): File "<stdin>", line 1, in ? Asser...

Python - Why the use of assert(required_param)?

I found this today while looking at a library for an API . def my_function(self, required_param=None): assert(required_param) ... Do cool function stuff Wouldn't it be easier to do this: def my_function(self, required_param): ... Do cool function stuff Or, am I missing something? The assert() of course gives you one un...

How to use Rhino.Mocks AssertWasCalled() correctly?

I can't find out what's the problem. I haven't found any documentation on AssertWasCalled on Rhino.Mocks site, so I have to ask the question here. What I do in my tests is I call _mocks.ReplayAll(), then one or more _mockedObject.AssertWasCalled() and then _mocks.VerifyAll(). But it tells me that "This action is invalid when the mock ob...

NUnit Nested Collection Comparison

Is there something similar to CollectionAssert.AreEquivalent() that works with nested collections? The following code... CollectionAssert.AreEquivalent ( new Dictionary<int, Dictionary<int, string>> { { 1, new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } } }, { 2, new Dictionary < i...

Java/ JUnit - AssertTrue vs AssertFalse

Hello all, I'm pretty new to Java and am following the Eclipse Total Beginner's Tutorials. They are all very helpful, but in Lesson 12, he uses assertTrue for one test case and assertFalse for another. Here's the code: // Check the book out to p1 (Thomas) // Check to see that the book was successfully checked out to p1 (Thomas) assertT...

C++ fputs Assert on Windows 2008 Server

In the below code the fputs(...) throws an assert when running on Windows Server 2008. I don't have this problem on a Vista or XP machine. I'm at a loss as to what is causing it? The assert is: Stream != NULL It seems to be random too, as sometimes it seems to succeed... as the log files get created. Can anybody help? void DLog::L...

JavaScript anti-silent techniques to indicate failure

What would be a good way to report errors in JavaScript instead of relying on nulls, and undefineds when errors do occur and a function is unable to proceed forward. I can think of three approaches: do nothing throw an exception assert Here's a simple example scenario - a function that credits a user account with the amount passed in...