Is it possible to execute TestNg tests in a JUnit TestSuite. I see a lot of web pages describing how to use TestNg to run JUnit but none the other way around.
No, only JUnit tests can be run in TestNG.
TestNG was initially developed as a replacement for JUnit with additional functionality and an emphasis on smooth migration. An ability to run JUnit tests was one of the tools for that smooth migration.
TestNG fully covers the functionality of JUnit and adds something new. And JUnit can not (currently?) emulate that difference in functionality.
You may check the comparison of these two libraries here.
Related
I want to write the business logic of my CodenameOne application using JUnit 5. But when I try to run any unit test in Intellij, the simulator is started with the app instead of the unit tests.
Did anybody figure out how to setup Intellij such that the unit tests can be run without triggering the Ant build?
Codename One has its own unit test API and test recorder, generally you should use that for your testing as it allows you to test everything including the GUI.
See this for further details on using the testing framework.
You could probably use JUnit for the pure business logic but I'm not sure what benefit it would provide.
We were using JUnit 4, but we had some problems with test grouping. For integration tests we had problems with running order. We had migrated to TestNG in February 2016.
Now we are starting a new independent module for our project and part of our team players wants JUnit 5. I believe it is much better than 4th (there are some new important features, but I see some problems too).
I do not want to use JUnit 5 because of fear of possible problems in our new application, because I have experience with 4th. But I have to be more flexible for the team, so before making a decision I need recommendations from users who have experience with JUnit 5.
TestNG objective is beyond unit test so it covers wider testing needs like Scenario Tests, Integration Test, Dependency Test, Ordering, Parallel Execution etc, but these feature are not supported in JUnit 5.
The JUnit 5 team have these above items in their road map, but they are extending a unit testing framework to support wider range of testing needs. Lets see how the new subsequent release of Junit 5 is able to address the wider testing need in comparison with TestNG
For Spring based application Junit fits best for doing the Unit and Integration Testing as it the default testing framework and Spring Provides lots of Test API with Mockito.
For general testing and Web Automation (Selenium) - TestNG is the de facto.
JUnit 5 introduced a lot of new features. Currently Intellij IDEA supports JUnit 5.
Take a look at article about integrating: Using JUnit 5 in IntelliJ IDEA.
There are some useful annotations now, like:
#Tag Used to declare tags for filtering tests, either at the class
or method level; analogous to test groups in TestNG or Categories in
JUnit 4
#DisplayName Declares a custom display name for the test class or test method
See more: JUnit 5 User Guide
My thought is that "JUnit is a framework for testing java applications and is typically implemented as plugins (to popular IDEs)", but can't it also be considered a standalone testing tool if implemented as a standalone (although it might be a stupid idea)?
No, JUnit is a testing framework.
You would still require a "runner" to run your JUnit tests, be it Maven or a similar.
There are stand alone runners available so you can execute tests without build tools or an IDE.
Is there a way to prevent the
<system-out><![CDATA ... ]]></system-out> to be included in the junit reports when using gradle java plugin and the test task ?
I run a lot of tests with heavy outputs, and generating the HTML report results in a Java Heap space.
The report generation is done by ant with the junit report task for the moment.
I'm integrating gradle in a heavy ant script, and it will take time to move everything to gradle.
During the transition phase, I would like to keep the junit report generation provided by Ant.
To my knowledge, there is no way to prevent system out from showing up in Gradle's JUnit reports. However, if reporting is done in Ant, you can disable Gradle's JUnit reports.
Is there any Eclipse plugin for Static analysis of Junits. I am looking for some best tool like PMD which checks for Junit practises and gives me a report on errors.
FindBugs has been described as a strong compliment to PMD and should cover JUnit tests since JUnit is still just Java. It's available from the University of Maryland.