Questions tagged [assertion]

An assertion is a software construct where the developer states ("asserts") a condition that he believes will always be true. If the condition evaluates to false in some languages an exception is thrown, in others a message is printed, and in others the program ceases to operate.

An assertion is a software construct where the developer states ("asserts") a condition that he believes will always be true. If the condition evaluates to false, in some languages an exception is thrown, in others a message is printed, and in still others the program ceases to operate.

Assertions can exist in most high-level languages (C, Java, etc...) as well as in register-transfer-languages (RTL) such as Verilog, System Verilog, and VHDL.

1445 questions
67
votes
11 answers

Java assertions underused

I'm wondering why the assert keyword is so underused in Java? I've almost never seen them used, but I think they're a great idea. I certainly much prefer the brevity of: assert param != null : "Param cannot be null"; to the verbosity of: if (param…
Dónal
  • 185,044
  • 174
  • 569
  • 824
59
votes
3 answers

xUnit Equivalent of MSTest's Assert.Inconclusive

What is the xUnit equivalent of the following MSTest code: Assert.Inconclusive("Reason"); This gives a yellow test result instead of the usual green or red. I want to assert that the test could not be run due to certain conditions and that the test…
Muhammad Rehan Saeed
  • 35,627
  • 39
  • 202
  • 311
44
votes
17 answers

Assert that a WebElement is not present using Selenium WebDriver with java

In tests that I write, if I want to assert a WebElement is present on the page, I can do a simple: driver.findElement(By.linkText("Test Search")); This will pass if it exists and it will bomb out if it does not exist. But now I want to assert that…
True_Blue
  • 1,387
  • 2
  • 10
  • 13
40
votes
3 answers

What are contracts (as proposed for C++17)?

I read about contracts in Thoughts about C++17 by B. Stroustrup and assisted a small presentation talking about them but I am not sure I have understood them really. So I have some interrogations and if it is possible to illustrate them with some…
coincoin
  • 4,595
  • 3
  • 23
  • 47
39
votes
4 answers

What does assert(0) mean?

I had a question like this on one of my exams and I'm still not too sure how to answer it. I understand that assertions are ways to test your program, however I'm not too sure what assert(0) is checking. Is this a trick question? It will always…
Smith Western
  • 393
  • 1
  • 3
  • 5
39
votes
4 answers

What is the use of the "-O" flag for running Python?

Python can run scripts in optimized mode (python -O) which turns off debugs, removes assert statements, and IIRC it also removes docstrings. However, I have not seen it used. Is python -O actually used? If so, what for?
zaharpopov
  • 16,882
  • 23
  • 75
  • 93
36
votes
10 answers

Best way to check that element is not present using Selenium WebDriver with java

Im trying the code below but it seems it does not work... Can someone show me the best way to do this? public void verifyThatCommentDeleted(final String text) throws Exception { new WebDriverWait(driver, 5).until(new ExpectedCondition()…
Roman Iuvshin
  • 1,872
  • 10
  • 24
  • 40
32
votes
4 answers

JMeter how to NOT fail 500 Internal Server Errors

I am using JMeter as a unit test tool, in parameterised calls where I expect some of the responses to be 500 internal server errors. I am using BeanShell Assertions to check the responses. I want some of the 500 internal server errors to NOT be…
Gazen Ganados
  • 665
  • 1
  • 7
  • 17
32
votes
3 answers

Is the .should('exist') assertion redundant on Cypress?

Let's consider the case where I need to assert if an element exists. There are 2 possible ways of doing this in cypress: 1) cy.get('button').contains('Save') 2) cy.get('button').contains('Save').should('exist') In both cases the test will fail if…
ITguy
  • 847
  • 2
  • 10
  • 25
32
votes
2 answers

Gulp AssertionError [ERR_ASSERTION]: Task function must be specified

I'm trying to customize a template for a demo of a webapp built on AngularJS using MacOS Sierra 10.13.6. I've installed Gulp but when I launch gulp serve return this error without launching the local server: assert.js:337 throw err;…
Ahmed Barkhia
  • 331
  • 1
  • 3
  • 5
31
votes
6 answers

Using assertion in the Linux kernel

I have a question about assert() in Linux: can I use it in the kernel? If no, what techniques do you usually use if, for example I don't want to enter NULL pointer?
macindows
  • 4,303
  • 4
  • 18
  • 9
30
votes
6 answers

Is actively throwing AssertionError in Java good practice?

Looking through Joshua Bloch's 'Effective Java - Second Edition', I stumbled upon the following code on page 152: double apply(double x, double y) { switch(this) { case PLUS: return x + y; case MINUS: return x - y; …
Mathias Bader
  • 3,585
  • 7
  • 39
  • 61
29
votes
7 answers

How to compare two Json objects using C#

I have two Json objects as below need to be compared. I am using Newtonsoft libraries for Json parsing. string InstanceExpected = jsonExpected; string InstanceActual = jsonActual; var InstanceObjExpected = JObject.Parse(InstanceExpected); var…
Nandakumar1712
  • 357
  • 1
  • 4
  • 11
29
votes
6 answers

How to assert the contents of an array, indifferent of the ordering

I have a minitest spec: it "fetches a list of all databases" do get "/v1/databases" json = JSON.parse(response.body) json.length.must_equal Database.count json.map{|d| d["id"]}.must_equal Database.all.pluck(:id) end This, however,…
berkes
  • 26,996
  • 27
  • 115
  • 206
27
votes
3 answers

CUDA: How to assert in kernel code?

What is the equivalent technique of an assertion in CUDA kernel code? There does not seem to be an assert for CUDA kernel code. I want a way to catch programmer mistakes easily in kernel code. A mechanism where I can set conditions that need to be…
Ashwin Nanjappa
  • 76,204
  • 83
  • 211
  • 292
1
2
3
96 97