assertions

What's the "upgrade path" from Assertion.AssertEquals ?

I've inherited some unit test code which is giving me a deprecation warning because it uses "Assertion.AssertEquals": warning CS0618: 'NUnit.Framework.Assertion' is obsolete: 'Use Assert class instead' However, I can't see the obvious method in the Assert class that I should be using instead? AssertEquals takes two objects and a messa...

Convenient strategies for assertion checks.

Some asserts are costly, some are better turned off at production code. At least it is not clear that assertions should be always enabled. In my application I would like to be able to turn on/off part of assertions on per-file or per-class basis. How to do it in C++? ...

Debug.Assert vs Exception Throwing

I've read plenty of articles (and a couple of other similar questions that were posted on StackOverflow) about how and when to you assertions, and I understood them well. But still, I don't understand what kind of motivation should drive me to use Debug.Assert instead of throwing a plain exception. What I mean is, in .Net the default res...

Assert difference of number of children in relationship in Ruby on Rails

My controller is able to create a child book_loan. I am trying to test this behavior in a functional test but am having a hard time using the assert_difference method. I've tried a number of ways of passing the count of book_loans to assert_difference with no luck. test "should create loan" do @request.env['HTTP_REFERER'] = 'http:...

rspec mocks: verify expectations in it "should" methods?

I'm trying to use rspec's mocking to setup expectations that I can verify in the it "should" methods... but I don't know how to do this... when i call the .should_receive methods on the mock, it verifies the expected call as soon as the before :all method exits. here's a small example: describe Foo, "when doing something" do before :a...

NUnit: Assert.Throws

How do I use Assert.Throws to assert type of the exception and the actual message workding. Something like this: Assert.Throws<Exception>( ()=>user.MakeUserActive()).WithMessage("Actual exception message") Method I am testing throws multiple messages of the same type, with different message and I need a way to test that correct m...

proper use of assert.h in debugging

Hi! c++ with visual studio 2008 if i use assert() from assert.h and compile in debug mode, the application crashes if the assert condition doesn't hold and it prints me in the console on what line in what file this happened. that's quite useful, but i'd prefere to trap into the debugger at this position instead, if the condition doesn'...

SMART ASSERT for C++ application?

Is it good to define a new macro that craters my need of showing failed assertion to user and with just enough information for developers to debug the issue. Message for user, what the user should do with this message at last information for the developer #define ASSERT(f) \ do \ { \ if (!(f) && AfxAssertFailedLine(T...

Can I write custom assertions in CxxTest?

I'm just starting to use CxxTest and would like to test whether a std::vector has been sorted correctly. Here's my test so far: void testSort() { std::sort(vec.begin(), vec.end()); // This could be any sorting function for (unsigned int i = 0; i < vec.size() - 1; ++i) { TS_ASSERT(vec[i] <= vec[i + 1]); } } Obviously, CxxTes...

JUnit: Enable assertions in class under test

I've been bit a few times by Java assert statements that didn't fail in the JUnit test suite because assertions weren't enabled in JUnit's JVM instance. To be clear, these are "black box" assertions inside implementations (checking invariants, etc) not the assertions defined by the JUnit tests themselves. Of course, I'd like to catch any...

Xunit: Perform all 'Assert'ions in one test method?

Is it possible to tell xUnit.net to perform all e.g. Assert.True() in one test method? Basically in some of our use/testcases all assertions belong logically to one and the same 'scope' of tests and I have e.g. something like this: [Fact(DisplayName = "Tr-MissImpl")] public void MissingImplementationTest() { // parse...

Why am I getting an assertion error?

#include <iostream> using namespace std; int main () { int size = 0; int* myArray = new int [size + 1]; cout << "Enter the exponent of the first term: "; cin >> size; cout << endl; for (int i = size; i >= 0; --i) { cout << "Enter the coefficient of the term with exponent " << i << ": "; cin >> myArray[i]; } for (int i =...

Enabling assertions in Netbeans

I wanna do something like java -enableassertions com.geeksanonymous.TestClass How do I do this? ...

RAILS - How deep does assert_raise check for an exception

Should the following test assert an exception was thrown? On my pc it doesn't and I want to know if this is expected behavior. def a raise RuntimeError end def b begin a rescue RuntimeError puts "bummer" end end test "assert this" do assert_raises RuntimeError do b end...

Borland Assertion failed in local_unwind()

I have a comms server that is supposed to run for an indefinite amount of time. However, it sometimes errors with Assertion failed: !"bogus context in Local_unwind()", file xx.cpp, line 2262 which is followed by Abnormal Program Termination after which pressing ok causes the program to disappear. This problem happens interm...

Why won't a Hashtable return true for "ContainsKey" for a key of type byte[] in C#?

Consider the following code: byte[] bytes = new byte[] { 1, 2, 5, 0, 6 }; byte[] another = new byte[] { 1, 2, 5, 0, 6 }; Hashtable ht = new Hashtable(); ht.Add(bytes, "hi"); Assert.IsTrue(ht.ContainsKey(another)); Why does this assertion fail? Being an array of a primitive type shouldn't use using the object reference, should it? S...

when to use assertion vs Exception

most of the time i will use exception to check for condition in my code, i wonder when is appropriate time to use assertion for instance, Group group=null; try{ group = service().getGroup("abc"); }catch(Exception e){ //i dont log error because i know whenever error occur mean group not found } if(group !=null) { //do something } ...

C++ Xcode assert evaluated in release

Hi! I'm quite new to Xcode (and Mac in general). I started a little iPhone project - coding in C++ whatever possible - and just noted that my assert(); commands are executed also in release mode. Is this a known problem and how do I solve it properly? thanks! ...

Best practices for multiple asserts on same result in C#

What do you think is cleanest way of doing multiple asserts on a result? In the past I've put them all the same test but this is starting to feel a little dirty, I've just been playing with another idea using setup. [TestFixture] public class GridControllerTests { protected readonly string RequestedViewId = "A1"; protected Grid...

Using assert within kernel invocation

Is there convenient way for using asserts within the kernels invocation on device mode? Thanks, in advance. ...