Which JUnit package to use on Assert? [duplicate] - junit

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
differences between 2 JUnit Assert classes
I have two junit-4.8.1.jars in my class path and my IDE's autocomplete is giving me the following two Assert classes:
junit.framework.Assert
org.junit.Assert
Which one should I use???

To quote a duplicate...
JUnit 3.X: junit.framework.Assert JUnit 4.X: org.junit.Assert
Prefer the newest one, especially when running JDK5 and higher with
annotation support.

I prefer org.junit package in all things JUnit. It's the source URL that the code comes from. The other is legacy that's left so it doesn't break old code.
Pick one and be consistent.

Niether, use MatcherAssert and Hamcrest with assertThat instead of assertTrue / assertFalse
MatcherAssert

Related

Can I execute all my Karate feature files more than once based on a parameter [duplicate]

This question already has an answer here:
How can we execute WebUI feature file against multiple browsers using parallel runner or distributed testing?
(1 answer)
Closed 1 year ago.
We have a requirement to run the entire test suite more than once considering different parameters.
Say, I have 5 feature files and each has 10 scenarios. I have a requirement to run these feature files twice one after the other.
There is a way to achieve this using Scenario Outline, which will execute each scenario for the number of parameters. But can we have all the scenarios run once for the 1st parameter and then all the scenario again for the 2nd parameter. Something like an Outline at Feature level.
Please suggest.
I think this should be done at the JUnit / Java runner level. Teams usually use tags to enable or disable features at run time.
Or you can create a "wrapper" feature that calls a second feature etc.
Otherwise please assume that what you want is not directly supported, you are welcome to contribute code to Karate if needed. My honest opinion is that this is not required in a testing framework, maybe you should just write code.
EDIT - see this answer, I think you will be able to figure out an approach based on it: https://stackoverflow.com/a/60387907/143475 - and keep in mind Karate supports a "dynamic" Scenario Outline.

vim comment/uncomment with one mapping [duplicate]

This question already has answers here:
What's a quick way to comment/uncomment lines in Vim?
(52 answers)
Closed 7 years ago.
I'm new(bie) in vim. I've got the following mapping to comment my python code :
nmap cc 0i#<ESC>
I would like to have the same mapping to uncomment a line. I think I need an function to check the first character of the line. Do you know how I could do the tricks ?
thanks.
edit : It's not the same as that question , I wonder how to do that without plugin.
You shouldn't attempt to implement this (poorly) yourself; this is a solved problem, and you can choose from several good plugins. See Comment Lines according to a given filetype for a list of plugins.
As a learning experience, attempting a mapping is fine, though. Here's one approach that uses :help map-expr to check the line for the existence of a comment first:
nnoremap <expr> cc getline('.') =~# '^#' ? '0x' : '0i#<ESC>'
PS: You should use :noremap; it makes the mapping immune to remapping and recursion.
There is this plugin. It's very good and he works for many languages.

Running junit tests in intelliJ in parallel [duplicate]

This question already has answers here:
Running JUnit Tests in Parallel in IntelliJ IDEA
(3 answers)
Closed 5 years ago.
Is it possible to run junit tests in intelliJ in parallel? If so, how do i do this?
I set the "fork" parameter to class level and this didn't do anything - actually, it made everything a bit slower, so i'm unsure what "fork" does that is beneficial?
Is it possible to do this just using intelliJ, or do i need some fancy test framework and all the hoo-hah that that would involve?
Finally, assuming this is at all possible, can one control the number of forks or threads or whatever they want to call it?
UPDATE: somebody has linked to a question that might answer this. I looked at that question prior to posting - I'm unsure what that question really "answers". It simply says there is an issue tracker and that this issue has been implemented in intelliJ. I don't see how to implement it anywhere.
UPDATE: What does "didn't do anything" mean?: it just makes things slower, which isn't v. useful. I mean, maybe your tests run blazingly quickly and you want to slow them down to appreciate some Bach? That is cool. I just want mine to run faster, I'm fed up of Bach.
You can make use of the junit-toolbox. This is an extension library for jUnit that is listed on the jUnit site itself.
This extension offers the ParallelSuite. Through this you can create with nearly no effort an AllTest class that executes the tests in parallel. The minimum AllTest could look like the code below, using the pattern feature introduced with junit-toolbox.
#RunWith(ParallelSuite.class)
#SuiteClasses("**/*Test.class")
public class AllTests {}
This will create as many threads for parallel execution as your JVM reports via availableProcessors. To override this you may set the system property maxParallelTestThreads.

Drawbacks of TestNG compared to jUnit? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I'm familiar with jUnit, and heard TestNG might be a solution to some of jUnit's annoyences - e.g. its insistence to create a separate instance of the test class per test, thus forcing me to use static field for objects I want to reuse between tests.
(Let's say you agree with me that this is a drawback, and not turn this question to something it's not)
What I'm asking here, is what drawbacks does TestNG have, compared to jUnit? Why not use TestNG, assuming this is a new project and there isn't any migration cost?
I'm the creator of TestNG. I'm not going to weigh in since I'm obviously biased, but I'm happy to answer any question you might have about TestNG.
Andy: thanks for your comment. FYI (you probably already know that but maybe the original poster doesn't), there is a TestNG Eclipse plug-in (which I develop in parallel to TestNG).
I personally have not encountered any significant drawbacks compared to JUnit.
At the start of a new project, my team switched to TestNG and had no regrets. TestNG is more powerful and supports broader usage than unit tests.
Some tools support JUnit but not TestNG. These are tools that I have not yet needed. For example:
Google's CodePro Analytix supports generation of JUnit unit tests.
The Eclipse IDE for RCP development supports run/debug configurations for "JUnit plug-in tests."
Being a huge supporter of TestNG I still see it is treated as being number 2 by tools authors. Many tools and libraries support JUnit from the very beginning, but you have to wait till they also implement support for TestNG. This might be a serious drawback if you plan to use some latest buzzing technology.
Over the years situation improved a lot. For example this used to be an issue with Spring, Gradle, or Maven Surefire but is no longer a problem because they all support TestNG now. Also all IDEs are treating both frameworks equally.
So, make sure the other technologies you plan to use play nicely with TestNG. This is rarely a problem, but still better make sure of it ahead.
For me the biggest problem is an integration with spring.
I do not like to extend TestNg classes and write code like this:
#Test
#ContextConfiguration(locations = { "classpath:spring-test-config.xml" })
public class TestSpring extends AbstractTestNGSpringContextTests {
Because usually I have my own hierarchy of test classes.
This was the main reason why I stopped using TestNg.
I must agree that parameterized test was very attractive for me. But they can be easily replaced with junit data-provider.
https://github.com/TNG/junit-dataprovider/wiki/Getting-started

Difference between function and method? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
method vs function vs procedure vs class ?
Can some one give the differences between a method and a function?
Both are the same. Both are subroutines and both can return a value. Only difference may be the attachment to class. Method sounds more attached to a class but again, people use to call the non attached ones too methods. So, in that aspect too they can be seen as same
In java, and c++, by convention a function is called a method if it is member of a class.
also see here
In many languages methods don't return values while functions do.