6
голосов
4ответов
3429 просмотров

why does junit4 not have Assert.assertArrayEquals() for double[]s?

There appear to be Assert.assertArrayEquals() methods in Junit4 for all primitives other than double, e.g. Assert.assertArrayEquals(int[] expected, int[] actual) and Assert.assertArrayEquals(char[] expected, char[] actual) but not Assert.assertArrayEquals(double[] expected, double[] actua...

4
голосов
1ответов
1720 просмотров

ASSERT fails on CDC SelectObject() call - What can I try?

I'm working on a multi-threaded win32 MFC application. We are rendering a map and displaying it in a pane in the user interface along with custom-rendered objects on top. It's slow to render (~800 ms), which is happening on the User Interface thread. I'm trying to move the rendering onto its o...

1
голосов
2ответов
358 просмотров

force asp.net assert to throw an exception?

My asserts aren't generating message boxes, sometimes they send a message to debug output and end the thread without giving me a more aggressive notification. How can I force all my Debug.Asserts to just throw, so I know that I see them?

263
голосов
9ответов
295964 просмотров

What is the "assert" function?

I've been studying OpenCV tutorials and came across the assert function; what does it do?

43
голосов
8ответов
39888 просмотров

Making Python's `assert` throw an exception that I choose

Can I make assert throw an exception that I choose instead of AssertionError? UPDATE: I'll explain my motivation: Up to now, I've had assertion-style tests that raised my own exceptions; For example, when you created a Node object with certain arguments, it would check if the arguments were goo...

1
голосов
5ответов
262 просмотров

Folding away assertions in C++ class?

So, in a non-class type of situation, I can do something like this: int val_to_check = 0; int some_func(int param) { assert(val_to_check == 0); return param*param+param; } int main() { printf("Val: %i\n", some_func(rand())); return 0; } If val_to_check is declared const instead, the ...

5
голосов
6ответов
683 просмотров

Waiting with a crash for a debugger?

When an assert fails or there is a segmentation fault, it would be very convenient that one of the following happens: Program ask whether to run a debugger. Program waits with crashing until debugger is attached. Program leaves something (core dump?) that we can resume execution from this point...

1
голосов
3ответов
266 просмотров

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++?

3
голосов
3ответов
829 просмотров

MFC Application Crashes while closing

I had a working MFC application (a dialog application), I deleted some of its button and added a new button, but now when it closes the application crashes. It fails in one of ASSERT() macro. The debug assertions fails on these lines File: afxtempl.h Line: 558 When I view that code it was somet...

19
голосов
9ответов
12324 просмотров

Exception vs. error-code vs. assert

I'm working on a library that generates reports of devices. The generate_report (const std::string& no) member function can fail due to various reasons: invalid report no. invalid state (the report_generator is a FSM) no device is active error during report generation Which error-handling...

0
голосов
2ответов
312 просмотров

How to write a macro that can take a parameter?

I want to use some NSAssert stuff and other things to enable better debugging in my app. NSAssert wants a string which it prints if the assertion fails. Nice, but useless unless you type a whole bunch of information in that string, which can become a big mess when done all over the place. So I w...

86
голосов
6ответов
28942 просмотров

Why does Assert.AreEqual(T obj1, Tobj2) fail with identical byte arrays

I have two identical byte arrays in the following segment of code: /// <summary> ///A test for Bytes ///</summary> [TestMethod()] public void BytesTest() { byte[] bytes = Encoding.UTF8.GetBytes(Properties.Resources.ExpectedPacketData); TransferEven...

13
голосов
7ответов
5325 просмотров

Python assert -- improved introspection of failure?

This is a rather useless assertion error; it does not tell the values of the expression involved (assume constants used are actually variable names): $ python -c "assert 6-(3*2)" [...] AssertionError Is there a better assert implementation in Python that is more fancy? It must not introduce a...

5
голосов
5ответов
1291 просмотров

Python test framework with support of non-fatal failures

I'm evaluating "test frameworks" for automated system tests; so far I'm looking for a python framework. In py.test or nose I can't see something like the EXPECT macros I know from google testing framework. I'd like to make several assertions in one test while not aborting the test at the first fa...

61
голосов
9ответов
38509 просмотров

Exception Vs Assertion

What is the difference between Java exception handling and using assert conditions? It's known that Assert is of two types. But when should we use assert keyword?

85
голосов
6ответов
27136 просмотров

Disable assertions in Python

How do I disable assertions in Python? That is, if an assertion fails, I don't want it to throw an AssertionError, but to keep going. How do I do that?

28
голосов
2ответов
21684 просмотров

Python : Assert that variable is instance method?

How can one check if a variable is an instance method or not? I'm using python 2.5. Something like this: class Test: def method(self): pass assert is_instance_method(Test().method)

25
голосов
4ответов
18864 просмотров

Usage of Assert.Inconclusive

I'm wondering how someone should use Assert.Inconclusive(). I'm using it if my unit test would be about to fail for a reason other than what the test is for. For example, I have a method on a class that calculates the sum of an array of ints. On the same class, there is also a method to calcula...

18
голосов
16ответов
2825 просмотров

Do you use assertions?

This is not really a "question" so I'm making it CW. The assert Keyword is great! It should make, feel your self more confident with the code you wrote, but, until today when I was creating a small test class ( <20 lines ) I realize a never use it since it was introduced. Heck! I bar...

17
голосов
3ответов
1928 просмотров

Should one override equals method for asserting the object equality in a unit test?

Let's say we are testing the result of a method by asserting the equality of all the properties of the result object with properties of an expected result object. Should we implement equals method and use Assert.AreEqual(expectedResult, actualResult)... But equals may mean something different in...

1
голосов
1ответов
1837 просмотров

Suggestions for python assert function

I'm using assert multiple times throughout multiple scripts, I was wondering if anyone has any suggestions on a better way to achieve this instead of the functions I have created below. def assert_validation(expected, actual, type='', message=''): if type == '==': assert expected =...

16
голосов
8ответов
6753 просмотров

Breaking into the debugger on iPhone

For assert macros in my iPhone project, I'm looking for a way to programmatically break into the debugger. On Windows (MSVC++), I can use __debugbreak() for this purpose. Invoking this function will stop my program, launch the debugger, and display a callstack of the line that called __debugbreak...

2
голосов
7ответов
473 просмотров

C/C++ an int value that isn't a number?

Can this ever happen ? 3 asserts, where one should activate. int nr = perform_calc(); assert( nr == 0); assert( nr > 0); assert( nr < 0); Can there be a case when the program doesn't activate the asserts on g++ 3.4.4. And no I don't have the possibility to change the code in order to pr...

35
голосов
7ответов
35727 просмотров

Ошибка утверждения мьютекса pthread

Я сталкиваюсь со следующей ошибкой в ​​непредсказуемое время в коммуникационном приложении на базе Linux (arm): pthread_mutex_lock.c:82: __pthread_mutex_lock: Assertion `mutex->__data.__owner == 0' failed. Google обнаружил много ссылок на эту ошибку, но мало информации, которая кажется...

4
голосов
9ответов
1040 просмотров

Должны ли мы утверждать создание каждого объекта в java?

Звучит как глупый вопрос с очевидным ответом :) Тем не менее я рискнул спросить, только будьте уверены вдвойне. Мы действительно используем утверждения, подобные приведенным ниже ArrayList alProperties = new ArrayList(); assert alProperties != null : "alProperties is null"; Проблем...

431
голосов
11ответов
171844 просмотров

Почему JUnit не предоставляет методы assertNotEquals?

Кто-нибудь знает, почему JUnit 4 предоставляет assertEquals(foo,bar), а не assertNotEqual(foo,bar) метод? Он предоставляет assertNotSame (соответствует assertSame) и assertFalse (соответствует assertTrue), поэтому кажется странным, что они не удосужились включить assertNotEqual. Кстати, я ...

194
голосов
9ответов
176531 просмотров

AssertContains в строках в jUnit

Есть ли лучший способ писать в jUnit String x = "foo bar"; Assert.assertTrue(x.contains("foo"));

3
голосов
2ответов
277 просмотров

Литералы или выражения в модульном тесте утверждают?

Вы предпочитаете буквальные значения или выражения в утверждениях в модульных тестах? Этот небольшой пример демонстрирует, что я имею в виду - обратите внимание на комментарии: [Test] public function fromXML_works() : void { var slideshow : Slideshow = SlideshowConverter.fromXML(xmlSample...

489
голосов
14ответов
233359 просмотров

Лучшая практика для Python assert

Есть ли проблемы с производительностью или обслуживанием кода при использовании assert как части стандартного кода вместо использования его только для целей отладки? Есть assert x >= 0, 'x is less than zero' лучше или хуже чем if x < 0: raise Exception, 'x is less than ze...

4
голосов
3ответов
833 просмотров

Как применить «Одно утверждение на тест» для условия отношения ИЛИ

Признано, что в утверждении используется «Одно утверждение на тест». Нехорошо писать утверждение, как показано ниже : Assert((foo != null) && (bar != null)); Лучший выбор: Assert(foo != null); Assert(bar != null); Вопрос в том, что, если утверждение: Assert((foo ...