Before/after parametrized test in JUnit5 - testing

I haven't been able to find a way how to run a custom method before and after a parametrized test.
Do you know if there is a way for JUnit 5?
Something like I saw for JUnit 4:
https://junit.org/junit4/javadoc/4.13/org/junit/runners/Parameterized.BeforeParam.html

Related

Skipping test steps in testng

I am following POM approach with Testng for designing my framework . Consider a scenario wherein the test case got failed in the nth test step inside a #Test method.Can anyone suggest how can I skip the remaining test steps(from n+1 onwards)?
Since I am automating the manual test cases, each #Test belongs to 1 test case and so I cannot split up the steps into multiple #Test methods. When the test step is failed, it needs to skip the next steps in that #Test method and proceed to the next test case.
Also I need the count of test steps skipped in the result.
Kindly help.
Looks like you are basically looking for something around what a BDD tool such as Cucumber provides you. Cucumber lets you create a .feature file which contains one or more scenario (You can visualize each of your scenario to be one #Test annotated test method).
You could then leverage one of the Cucumber integrations i.e.,
Choose either JUnit (or)
Choose TestNG integration
and let one of these run your BDD tests.
Here when a particular step fails, then all subsequent steps would be aborted (which is what you are asking for)
Outside of Cucumber, I dont think you can have this done via any other mechanism. The reporting needs (such as how many steps were skipped etc.,) can be fulfilled by any cucumber based reports.
You should start from here : http://docs.cucumber.io/guides/10-minute-tutorial/

Does Codeception have an equivalent to PHPUnit's "strict coverage"?

When using PHPUnit, you can annotate a test case with #covers SomeClass::someMethod to ensure that only code inside of that method is recorded as covered when running the test. I like to use this feature because it helps me separate code that was incidentally executed during a test from code that was actually tested.
After using Codeception to implement some acceptance tests for my project, I decided I would rather use it than PHPUnit to run my unit tests. I would like to remove PHPUnit from the project if possible.
I am using Codeception's Cest format for my unit tests, and the #covers and #codeCoverageIgnore annotations no longer work. Code coverage reports show executed code outside of the methods specified with #covers as covered. Is there any way to mimic that "strict coverage" functionality using Codeception?
Edit: I have submitted an enhancement request to the Codeception project's Github.
It turns out that strict coverage was not possible using Cest-format tests when I asked the question. I have implemented it and the pull request has been merged.
For anyone migrating tests from PHPUnit and looking for this feature as I was, this means that a later release of Codeception should provide support for #covers, #uses, #codeCoverageIgnore, and other related test annotations.
The current version (2.2.4 at the time this was written) doesn't support it but 2.2.x-dev should.

How to skip Clojure Midje tests

If I have a Clojure test suite written using the Midje testing framework, how do I skip individual tests? For example, if I were using JUnit in Java and I wished to skip a single test, I would add an #Ignore attribute above that test method. Is there an equivalent to this for Midje?
I realise that I could add a label to my test metadata and then run the test suite excluding that label. For example, if I labelled my test with ":dontrun", I could then run the test suite with "lein midje :filter -dontrun". This would involve a change to my Continuous Integration task that runs the test suite though, and I'd prefer not to do this. Is there an equivalent test label of JUnit's #Ignore so that I only need to change the Midje test code and not change my Continuous Integration task?
future-fact does what you want, just substitute (or wrap) your fact with it:
(future-fact "an interesting sum"
(sum-up 1 2) => 4)
This will, instead of executing the test code, print a message during the test run:
WORK TO DO "an interesting sum" at (some_tests.clj:23)

Is there a way to repeat some tests for a week by using testNG framework?

I need to run a test for a week. I tried several ways.
1. Use factory to add test. All cases run after the factory method finished. So I could not judge how many tests to add.
2. Changed TestNG class, rewrite some methods. Only works when I need to repeat all tests.
Is there any good way to implement that?
Have a thought of change both XmlSuite and testNG class. Add isRepeat and time2Repeat properites for XMLSuite and change testNG method runSuitesSequentially to support repeat running. Will have a try later.
The solution might work, but feels like a hack. If anyone could provide more decent way, please provide your thoughts.
Thanks!

Using categories vs parametrized tests from JUnit with selenium rc

I currently have a set of unit tests which are run with the Parametrized test harness built into JUnit. As I do not want to create a new Selenium instance with each test case (i'd rather log in, navigate to a screen, and run a set of tests), I am looking at other options in which I can automate my tests.
I want to set up different tests in different classes which all leverage the same test method.I found the Categories also offered by JUnit however as this appears to be a way to set up a TestSuite, I am not sure if this will help.
I guess the short question is, if I have a bunch of selenium tests spread out to different classes is there a way I can get these tests to run in one test method specified elsewhere?
You can create test suite in Junit over there you can write your different classes containing ur tests.
In Junit 4 a test suit is written like this.
import org.junit.runners.Suite;
#RunWith(Suite.class)
#Suite.SuiteClasses({TestClass1.class, TestClass2.class})
public class TestSuite {
//nothing
}