Assertions
See original GitHub issueIs there a way to use Java assertions?
Using a Python3 kernel and the line:
assert(1==2)
an AssertionError is returned:
AssertionErrorTraceback (most recent call last)
<ipython-input-2-000000000000> in <module>()
----> 1 assert(1==2);
AssertionError:
Using the IJava kernel and the same line, there is no return value or exception displayed.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Assertion Definition & Meaning - Merriam-Webster
The meaning of ASSERTION is the act of asserting or something that is asserted. How to use assertion in a sentence.
Read more >Assertion (software development) - Wikipedia
In computer programming, specifically when using the imperative programming paradigm, an assertion is a predicate connected to a point in the program, ...
Read more >Assertions in Auditing - Overview, Importance, and Types
Assertions are claims that establish whether or not financial statements are true and fairly represented in the process of auditing.
Read more >Programming With Assertions - Oracle Help Center
An assertion is a statement in the Java programming language that enables you to test your assumptions about your program. For example, if...
Read more >ASSERTION | definition in the Cambridge English Dictionary
a statement that you strongly believe is true: I certainly don't agree with his assertion that men are better drivers than women.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Assertions in java are a bit different, there is the
assert
keyword but it is disabled by default. To enable it the-ea
flag must be passed in the jvm arguments. In the IJava kernel this can be done by editing thekernel.json
and adding the-ea
flag to theargv
list but this makes your notebooks less reproducible as users would require the same setup.What I would recommend is use a library like junit assertions which are common in java unit testing and easily included with the maven magic.
Run a cell with the following to include all of the
assert
methods from junit to the static space in your notebook:Use the assertion methods like the following:
which is the same as the following pure java code if -ea is enabled:
Thanks for following up! Current preliminary testing seems to indicate it works. It will get its main workout when we run >400 students and their homeworks through it in December 😃 - we will keep you posted.