How to document the failing JUnit tests - java

I have developed an Automation framework with JUnit for our API Testing. Here I have created a separate class for each API listing multiple unit tests for that API.
I want to list each failing JUnit test case in some separate file so that I can easily track the failing test cases. Can anyone suggest how can I do it?

Thank you all for your suggestions. I replaced the JUnit with TestNG, Integrated the Surefire plug-in and Jenkins CI as well, and my framework is working the same that I intended in the beginning.

Related

JUnit implementation of QAF

Good afternoon.
Is it possible to implement the work of QAF with JUnit?
For example, i want to use qaf-gherkin in my project, but it's build on JUnit + Cucumber.
As I see, there is a similar question, but there is no description about project and on which test framework it was based.
QAF built upon TestNG. If you are using Junit for Java you can run using TestNG by setting junit="true" in configuration file. However for migrating cucumber to QAF it should not impact current runner is either Junit or TestNG until you are using any specific features of Junit. All you need to start using QAF following documentation. You don't need to write or use additional java class to run your tests because it is taken care by QAF. All you need to do is create xml configuration file for to run your BDD
Because QAF provides all testing needs together you don't need to relay on multiple frameworks (junit and cucumber in your case).

TESTING SELENIUM, TESTNG Questions

I am an entry level tester, mainly been doing manual testing for a company in the UK following scripts on a spreadsheet which I have written in the BDD format, however, I have been learning some automation on the side as that's what I want to move into full time. I have some questions though which are as follows.
I've been using Selenium web driver + java bindings to make simple tests such as logging in or filling out a registration form, i've also set up log4j but only basic to record low level recording. I have now come across testNG. My main question is this framework used by testers? or developers? Is testNG only for unit tests? or UI tests?
From what i've learnt so far the developer does the unit and component tests and the tester does the services/ui tests is this correct?
Unfortunately I was put into a team of developers and not testers as this is my first job outside of university. So I haven't had the chance to learn from other testers. There was no plan for me when I started just that I was going to be the first tester in this development team without any prior testing knowledge.
Which is why I need a bit of guidance on these issues.
My main question is this framework used by testers? or developers? Is
testNG only for unit tests? or UI tests?
TestNG can be used for both, developers and automation testers, it is a tool that can operate over and together with Junit, basically in some cases is being used to create the concept of test suite, that allows to split all the test cases based on specific criteria (time, module, complexity). Also this framework can be used in unit testing and integration testing as well as ui-testing.
TestNG also in some cases replaced Junit entirely, whit this approach you will have a framework with some out of the box capabilities as DataProviders, Multi threading support and other, you could check this link, consider this as and powerful option for Junit.
From what i've learnt so far the developer does the unit and component
tests and the tester does the services/ui tests is this correct?
Unit testing which I consider very similar as "component test" is being done by the developers. If you have web services or a REST API, developers sometimes are in charge of create some test using integration testing, basically verify that services are working as we expected, returning JSON/XML with the correct format and other kind of validations.
Testers also could check services, using tools such as Jmeter, SOAP-UI, they check more things related to the business logic.
Finally I would said UI test is being done in most of the places by the manual and automation testing team, in places where is no QA department this tasks also belongs to the DEV team.
In order to run tests you need to have a test runner it could be anything, most common in java world is JUnit and TestNG, with those frameworks you can run the tests which annotated by #Test tag, also you can group the tests the way you want it and run them in parallel.
Testers use it to run Selenium tests and do assertions, even though for assertions it is good to have knowledge of hamcrest matchers. Also it providing you reports after tests been completed.
Developers would use same frameworks for unit testing purposes.
Check out guys from toolsqa.com they have pretty comprehensive tutorials on using Selenium with TestNG.
TestNG is basically used by developers for doing unit testing, I agree. But it is also widely used by system test automation using Selenium. This framework is inspired by JUnit framework, and most of the automation test developers use this framework because of its advantages and more added features to support reporting.
I can say following advantages I got by using this framework:
1.Support for parameters.
2.Supports dependent methods testing.
3.Test configuration flexible. Supports powerful execution model.
4.Embeds BeanShell for further flexibility.
5.TestNG has a more elegant way of handling parameterized tests with the data-provider concept.
6.For the same test class TestNG support for multiple instances.
7.Extendibility of using different Tools and plug-ins like Eclipse, Maven, IDEA etc.
8.Default JDK functions for runtime and logging (no dependencies).
9.Supported different Annotations like #BeforeSuite, #AfterSuite, #BeforeClass, #AfterClass, #BeforeTest, #AfterTest, #BeforeGroups, #AfterGroups, #BeforeMethod, #AfterMethod, #DataProvider, #Factory, #Listeners, #Parameters, #Test.
The most beautiful part I found in testNG is, using data provider, i can easily read test inputs and expected results from excel. And I can able to see the Results of Pass/Fail and skip test cases in an emailable format.
For testing a system, we don't need any training/extra classes. Just if we know the system requirements, and this as a end user what they want from the system and start testing. If any deviations found in the system behavior and are not as per the expectations of user. Then mark it as an issue and raise a defect and track it until it get resolved. Retest the same and confirm that the system is working as per the expectations. even at the Unit test level this principle holds the same. But only the difference is that we can do Structure based testing there.
To your questions ..
1.My main question is this framework used by testers? or developers? Is testNG only for unit tests? or UI tests?
Answer = Test NG can be used for unit testing as well as UI testing. the advantage of test NG over JUNIT is that you dont need to write code for test result reporting.

Can we write functional tests using junit?

I understand Junit is intended for unit testing. Can we write functional tests using junit as well? Like we write Integration tests using junit.
If functional tests are not going to be read by a non-tech user (aka customer) then it looks like a overkill to use tools such as Cucumber, Fitnesse etc. Given that I have a good knowledge of Junits - i want to reuse the same?
Also I notice it is possible to write functional tests using TestNG - Is it a good idea if junit is not suitable.
you can write any sort of test using junit. for example have a look at arquillian, which can boot a whole j2ee container from junit for testing, or fest, which enables swing UI testing from within junit, or use a selenium junit4 runner to test web applications from junit (combine with arquillian to boot the web application 1st :-) )

How to configure and run a Mockito test

I am working on an Android app which has some pure java based components that i want to test using Mockito.
I have some questions about configuring Mockito with my code base.
Should I create a test project in my code base?
Does Mockito has anything to do with JUnit? Do i need to include JUnit libs as well?
How do i run the Mockito test from Eclispe as opposed to JUnit test which is far more easier to run by doing Run As-> JUnit Test.
Kindly suggest some tutorial that could demo the setup and running of tests.
You don't need to create a separate test project, but you can if you want to. Most people do it by creating a separate test folder in the same project. Whether you have a separate test project or just a test folder, you should replicate your package structure inside your test folder, so that each test class is testing an application class in the same package.
Yes. Mockito is designed to be used with JUnit, or with some other testing framework, such as TestNG. Most people use it with JUnit. Most of the examples on the Mockito web site use JUnit. So, yes, you'll need the JUnit libraries, or the libraries for whatever other testing framework you choose.
A Mockito test is a JUnit test (or a TestNG test, or whatever). So there's no "far more easier to run", as you put it. Just write a JUnit test that uses Mockito, and run it in the same way as any other JUnit test.
Start with the Mockito web site and Mockito repository.

Migrating from Junit to TestNG

I need to migrate a bunch of test scripts from Junit to TestNG , So is there any utility or a runner does TestNG provides to run Junit test scripts ? also I am currently using Maven .
If possible Can someone share the snippet on how to do it .
I understand that it is a very old post, but I hope this would be useful if anyone is looking to migrate to TestNG.
I have a spring application and my JUnit tests uses different runners and tags like
- SpringJUnit4ClassRunner
- PowerMockRunner
- EasyMockRunner
- #ContextConfiguration.
Junit works with #RunWith tag where as TestNG requires extending classes AbstractTestNGSpringContextTests(for #ContextConfiguration), PowerMockTestCase(for PowerMockRunner), ..etc. Though there were multiple options provided(extending, configuration, other annotations) in some cases, some of the options didn't work and extending only worked. If the test class requires extending it may not work for some tests as the test might be already extending another base class and you need to refactor the tests and it may not be worth.
My 2 cents is that JUnit5 has some of the missing Junit4 features of TestNG and see if that solves the problem before jumping to migrating to TestNG.
The official document for Migrating from Juit to TestNG can be found here. Please take a look.

Categories