Questions tagged [assert]

An assertion is a statement, which aborts a program when it evaluates to false. Assert is typically used for debugging and situations which should never happen.

It is normally bad practice to use asserts in deployed software, because it typically provides information that is useful only to programmers; exceptions are preferred in this case. Also, assertions are not for use in validating input or in other situations where exceptions are preferred.

However, asserts can be used frequently when designing, to make sure that design requirements are met (for example, when designing-by-contract), and in debugging to make sure that code which is incorrect fails as quickly as possible. Assertions often give line numbers and file names, which makes tracking down where code failed easier than with other methods like core dumps.

C and C++ have assert in "assert.h". Most other languages have assert as a built-in (Python, Ruby, Java, and others).

2706 questions
1
vote
1 answer

Is it possible to test if a javascript function is a constructor?

I'd like to test if a function is a constructor (meant to be called with new), or just a regular function that should be called literally. This very well may not be possible, I could not find anything on the matter, but wanted to see if it is…
Jim Buck
  • 2,383
  • 23
  • 42
1
vote
1 answer

Assert that a property is not configurable

Given an object obj, how can I assert that its property prop is not configurable? First, I thought I could use getOwnPropertyDescriptor: if(Object.getOwnPropertyDescriptor(obj, prop).configurable) throw Error('The property is…
Oriol
  • 274,082
  • 63
  • 437
  • 513
1
vote
2 answers

Confusion with Soft asserting if a message is present

I am automating a form, the scenario is, when an invalid entry is given, the message 'Success' shouldn't appear I tried to check this using s_assert.assertEquals(driver.findElement(By.xpath("//div[contains(.,'Succes')]")).isDisplayed(),…
Shari
  • 123
  • 1
  • 1
  • 9
1
vote
2 answers

How collect Assert in loop and get result in end of test

I have a task to collect all the links of site, go to and check on each page, there is no error. The problem is that if there is an error on any page, the test is terminated. I want to have checked all the pages and at the end of the test to get the…
BCR
  • 71
  • 4
1
vote
2 answers

Make an element optional/mandatory based on another element using xsd:assert

I believe XSD 1.1 has asserts that allows conditional logic. I have a schema like this:
user972391
  • 321
  • 1
  • 4
  • 20
1
vote
0 answers

Is there any way to assert valid sha1 ,valid epoch timestamp and positive integer in python without using any thrid party library?

Is there any direct way to assert valid sha1 ,valid epoch timestamp and valid positive integer in python.I am bound to use native python and no third party libs.
1
vote
4 answers

Multiple arrangements/asserts per unit test?

A group of us (.NET developers) are talking unit testing. Not any one framework (we've hit on MSpec, NUint, MSTest, RhinoMocks, TypeMock, etc) -- we're just talking generally. We see lots of syntax that forces a distinct unit test per scenario, but…
lance
  • 16,092
  • 19
  • 77
  • 136
1
vote
1 answer

Is it possible to check if an interface is activated in pcap?

I am making a basic packet sniffer using pcap.h. While I was unit testing the function that called pcap_dispatch, I gave it non-activated interfaces and invalid interfaces. pcap_dispatch return -3, and as far as the man pages for pcap_dispatch…
user2738698
  • 520
  • 7
  • 19
1
vote
2 answers

Django: How do I use assert... without showing a system error page?

I'm new to Django and have some code in my views.py like this: try: myfunction() except: assert False, sys.exc_info()[0] This is very helpful because I get an email with lots of useful info if there's an error. The problem is that it also…
FunLovinCoder
  • 7,597
  • 11
  • 46
  • 57
1
vote
1 answer

Is there (already) a way to compare 2 model instances, field for field, to see if they are equal?

I'm trying to make an assertion inside one of my tests that the fields from a model have not changed. I know that philosophically this is incorrect, but since i control all the variables i need to know about, i just want to check that my DB entry…
vlad-ardelean
  • 7,480
  • 15
  • 80
  • 124
1
vote
1 answer

Superagent 'request' object is being redefined as function?

I'm trying to put together a supertest-based integration test suite (run by Mocha) that pings our REST API and validates the response. However, my test doesn't seem to be running as expected: var assert = require('assert') var should =…
Craig Otis
  • 31,257
  • 32
  • 136
  • 234
1
vote
1 answer

Using Assert to compare two objects

Writing test cases for my project, one test I need is to test deletion. This may not exactly be the right way to go about it, but I've stumbled upon something which isn't making sense to me. Code is like this: [Test] private void DeleteFruit() { …
baron
  • 11,011
  • 20
  • 54
  • 88
1
vote
0 answers

angular.js Assert error throw async

I'm testing an angular.js app using karma with sinon-chai. I need to test a code like this: var sync = function() { async.then(function() { // success }, function() { throw Error('foo'); }); } sync is the function I want to test.…
Drakson
  • 41
  • 3
1
vote
2 answers

return a return in javascript

I want to write a assert() function in Js. Something like this: assert = function(condition, message) { if(condition) { console.log(message); } else { return return; } } But it's not true. We can write it like…
ali
  • 85
  • 1
  • 1
  • 9
1
vote
0 answers

Should I put assertions inside object's methods or writing and calling a check representation fuction is enough?t

I wonder if writing a check representation function for an object and calling it while testing is enough to check the object's internal state corectness or should I also put assertions inside methods? Or maybe I should only use assertions inside…
1 2 3
99
100