Skip to main content

Questions tagged [assertions]

Assertions enables you to test your assumptions about your program. For example, if you write a method that calculates the speed of a particle, you might assert that the calculated speed is less than the speed of light.

0 votes
1 answer
272 views

In my experience, it is customary to place local variable declarations at the beginning of their scope. Several questions in this forum ask whether this needs to be so, and their answers tend to agree ...
Severo Raz's user avatar
6 votes
7 answers
4k views

Say you want to test an update capability across a CRUD api. Test A updates a field, queries it, and asserts that it now has the value from the update. Knowledge about the starting value (and that it ...
candied_orange's user avatar
20 votes
8 answers
9k views

Let's consider the following test. [Fact] public void MyTest() { // Arrange Code var sut = new SystemWeTest(); // Act Code var response = sut.Request(); // Assert ...
BAmadeusJ's user avatar
  • 326
-1 votes
1 answer
137 views

I recently finished developing a piece of software in python where learning models and data processing procedures are contained within different class objects that succeed to each others (modules). As ...
JrCaspian's user avatar
  • 125
-1 votes
2 answers
1k views

I have a function to be tested fn doNothing(Student student) { //do some other operations here. but student is unmodified return student; } And my unit test is var student = new Student("...
Santhosh Thamaraiselvan's user avatar
14 votes
14 answers
8k views

Take this constructed example: def fetch_person(person_id, country_code=None): if is_fully_qualified(person_id): return person_source_1.fetch_person(person_id) else: return ...
André Christoffer Andersen's user avatar
6 votes
5 answers
8k views

I'm working in a large company and am doing my first Java project here. We have certain code style guidelines. In the Java guideline, it is said that "assertions are only intended for debugging ...
Green 绿色's user avatar
31 votes
9 answers
10k views

In The Pragmatic Programmer, the authors write: One of the benefits of detecting problems as soon as you can is that you can crash earlier, and crashing is often the best thing you can do. The ...
samfrances's user avatar
  • 1,095
7 votes
5 answers
2k views

Sometimes when I look at other people's code I see functions that make a bunch of assumptions about the inputs but do not explicitly assert their assumptions. For example, look at the code below: def ...
jss367's user avatar
  • 263
0 votes
2 answers
481 views

I usually do Javascript and I like putting console.assert liberally in my application. It throws an error if the first argument is falsey. E.g.: console.assert(price > 0, 'Price isn\'t above 0') ...
Leo Jiang's user avatar
  • 117
4 votes
4 answers
508 views

I have got a project in C++. Each of my classes has a method void assert_good() const. The usage of that method is solely for debugging purposes: if the object is an inconsistent/impossible internal ...
shuhalo's user avatar
  • 231
3 votes
3 answers
156 views

A new feature is being developed. I want to test this feature in different scenarios. We have existing tests that correspond to this scenario (but they test other features). Should I : insert new ...
Wenneguen's user avatar
  • 139
7 votes
4 answers
1k views

Let F(x) be a function that calls G(x), in which x must be greater than 0. If G already does assert(x > 0), should F do it as well?
Martel's user avatar
  • 615
0 votes
1 answer
845 views

I have data structure queue with 2 operations: typedef struct queue queue void enqueue(queue *q, void *elem); void *dequeue(queue *q); queue *read_from_file(const char *path); I want to write ...
Some Name's user avatar
  • 121
1 vote
2 answers
34 views

Imagine a game that needs to score words. A words needs to be scored immediately, in a list of words or even in a list of words from list of players. I've created a scoring module which has the ...
Sven's user avatar
  • 186

15 30 50 per page