I am writing a series of automated tests for my e-commerce company, specifically checkout tests. I need to write the exact same set of tests using a (fake) Visa, Discover, AmEx, and MasterCard. I would love to be able to write a set of tests in one or more classes and then, during the same test run, repeat the tests again only with slightly different inputs (i.e., the credit card numbers). Is there anyway to do that? I am already running these tests in parallel using <parameters> in the testng.xml, but I want these checkout tests to run sequentially as a part of the entire test run for a particular browser, but those test runs on different browsers are ran in parallel (which I already have accomplished).
Read up on the #DataProvider annotation and how to use it in the TestNG documentation. It's what makes TestNG special. The data provider method will send as many rows of data to a test method as you want.
Related
I want to build a tool in java, where I can see the progress of my Junit test suite execution. Like below.
Current executing class.
How many test cases completed(Passed, Failed)?
How many test cases pending?
From this information, I want to build a graphical report.
How to start?
The preferred external facade seems to be JUnitCore, which offers a series of useful run(...) overloads. Call JUnitCore.addListener with a RunListener implementation and you should be able to get the notifications you need.
Note that the total number of test cases pending may not be easy to get ahead of time; the test count is available as part of the Description object but by default JUnit doesn't seem to create all the runners and Descriptions until immediately before their run.
I am really new to Fit/Fitnesse and, in general, to test automation.
I am trying to use them from Eclipse.
I have several question about it:
is there a way to obtain the html tables that Fitnesse pass to Fit?
once I write several tests with Fitnesse, is there a way to call them several times from Java without clicking on the Test button of the wiki?
About passing objects from one table to another in a flow. I read about symbols but it seems that, in java, they works only with ColumnFixturewhile I would like to use DoFixture. how to do this?
Finally,is if there is any plugin for eclipse you suggest to use with Fit/Fitnesse?
Regarding you question 2: I would recommend using the JUnit integration (#RunWith(FitNesseRunner.class) to run the test page (or a suite) as a unit test from Eclipse. This also gives you the ability to debug inside your fixture code.
It takes a bit of configuration to get it running 'just right'. In my pre-packaged FitNesse I provide a unit test FixtureDebug where you only have to enter the test name (and you can also use that to run your tests on a build/continuous integration server).
I have 1000 junit tests and one "bad" test that is modifying a shared resource causing a subsequent test to fail. It passes if run alone. I'm looking for a Maven plugin or Java application or tool that will take as input a test class name. It will then run the 1000 tests in various combinations until it finds the "bad" test. Assume it is one "bad" test.
As you may noticed, writing dependant tests IS the problem ! Every solutions would be a workaround, maybe with side effectfs, complexity the first one.
Assuming you REALLY can't change that, you may have different strategies to solve your issue, but they are not necessary related to maven :
Ordering
Order your test to run the "bad one" at the end ... be carefull that you me affected again if you have a second bad test !
User TestNG instead of JUnit and #Groups and #AfterGroups annotations to split your tests and run them as you want
Use #AfterClass and BeforeClass with a test suite: Cleanup after all junit tests
Manually describe a Test Suite (not sure if you can achieve what you want)
Provide good data
Use setUp and tearDown methods to prepare and clean data in order to always have a stable environment, on each tests classes
Rollback the test that modify you resource (pretty the same thing indeed)
Step back thoughts :
Just a piece of minds :
If you cannot run tests independently, they are not unit tests.
In junit test, should I create another test suite named as ExampleBAT to do this, and this test suite contains the selected test cases?
The BVT/BAT is a short set of tests which is done after the build and exercises the main functionality. So for (large) applications, JUnit might not be the right choice for this kind of tests. I'd design those test to be performed by hand or a different test framework which is capable to automate tests for applications or systems.
The BVT/BAT just proves, that the build was good enough to create a useable application (can be executed, user interface is accessible, can load data from database, ...).
Our application depends on numerous resources that are provided by another system.
To ensure the existence of those resources, we currently have a JUnit test case (probably more an integration test), that takes a list of all the resources as a textfile, fetches each and tracks success/failure.
This is a very long running testCase that is not very "tool friendly". What we would really like to have is something along the lines of one test-method per resource.
I am aware that this is not what JUnit was meant to do. But is there a way to generate those testmethods on the fly?
Maybe something a bit more "elegant" than writing a perl-script to generate hundreds of methods?
Thanks a lot!
You may want to look at parameterized tests. This is easier to achieve in JUnit 4, though can be done in JUnit 3. See this question for code: JUnit test with dynamic number of tests
This: http://github.com/adewale/cq-challenge-markup/blob/b99c098f0b31307c92bd09cb6a324ef2e0753a0b/code/acceptance-tests/AcceptanceTest.java is an example of a class that dynamically generates one test per resource using the JUnit4 #Parameterized annotation
You might want to take a look at the TestSuite class, and creating your own instance (rather than letting one of the junit runners just run all the tests in a certain dir) and/or subclassing it - the TestSuite has methods to programmatically addTests to it, and then you can run all the tests within the suite.