DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > 7 Test Frameworks To Follow in 2021 for Java/Fullstack Developers

7 Test Frameworks To Follow in 2021 for Java/Fullstack Developers

It is time to learn new test frameworks in 2021 to improve your code quality and decrease the time of your testing phase. Let's explore 6 options for devs.

Sylvain Leroy user avatar by
Sylvain Leroy
CORE ·
Sylvain Leroy user avatar by
Sylvain Leroy
·
May. 17, 21 · Java Zone · Analysis
Like (5)
Save
Tweet
8.62K Views

Join the DZone community and get the full member experience.

Join For Free
It is time to learn new test frameworks to improve your code quality and decrease the time of your testing phase. I have selected six testing frameworks that sound promising. Some have existed for quite a long time but I have not heard about them before.

At the end of the article, please tell me what you think about them and what your favorite ones are.

Robot Framework

Robot Framework is a generic open-source automation framework. It can be used for test automation and robotic process automation (RPA).

Robot Framework is open and extensible and can be integrated with virtually any other tool to create powerful and flexible automation solutions. Being open-source also means that Robot Framework is free to use without licensing costs.

RoboFramework: code

RoboFramework: code

 

RobotFramework: stack
RobotFramework: stack

The RoboFramework is a framework to write test cases and automation processes. It means that it may replace your classic combo Selenium + Cucumber + Gherkins. To be more precise, the Cucumber Gherkins custom implementation you wrote will be handled by RoboFramework and Selenium invoked below.

For the Java developers, this framework can be executed with Maven or Gradle (but less mature for the latter solution).

Testcafé

Testcafé is another E2E testing framework like Protractor or Cypress.

It provides a light DSL over the Browser API to write concise tests. It does not require WebDrivers; it uses Node.JS and the browsers installed on the machine. In a sense, it may not be the best solution for CI/CD environments but it is quite easy to use. It is still possible to use headless browsers for advanced users (and for CI/CD). It also supports mock HTTP requests that are also great to make tests on a smaller portion of your scenario. Last but not least, the framework is supposed to handle the timeouts and sleep pause between the browser actions automatically.

Testcafé code

Testcafé: code

JUnit Extension Random beans

https://glytching.github.io/junit-extensions/randomBeans

This JUnit extension integrates RandomBeans to enable your tests to integrate POJO generation with dynamic values.

Person person = random(Person.class); 

Too often, tests are using fixed static data and are too long to read and maintain. With this extension, you may fill out your POJO with random values and ensures that your tests are validating properly their results.

JavaScript
 




x
17


 
1
@ExtendWith(RandomBeansExtension.class)
2
public class MyTest {
3

          
4
    // injected with a random String    
5
    @Random private String anyString;
6
    
7
    // injected with a random, fully populated instance of DomainObject    
8
    @Random private DomainObject fullyPopulatedDomainObject;
9
    
10
    // injected with a random, partially populated instance of DomainObject    
11
    @Random(excludes = {"wotsits", "id", "nestedDomainObject.address"})
12
    private DomainObject partiallyPopulatedDomainObject;
13
    
14
    // injected with a List of random strings    
15
    @Random(type = String.class)
16
    private List<String> anyList;
17
}


JUnit Quickcheck

junit-quickcheck is a library that supports writing and running property-based tests in JUnit, inspired by QuickCheck for Haskell.

To be more concrete, you define properties or invariants, and they are checked on random values produced by generators. So you can use define properties on objects and provide a generator that will initialize the POJOs with random values if possible.

Rather than testing such properties for all possible inputs, junit-quickcheck and other QuickCheck kin generate some number of random inputs and verify that the properties hold at least for the generated inputs. This gives us some reasonable assurance upon repeated test runs that the properties hold true for any valid inputs.

Java
 




xxxxxxxxxx
1
12


 
1
 import com.pholser.junit.quickcheck.Property;
2
    import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
3
    import org.junit.runner.RunWith;
4

          
5
    import static org.junit.Assert.*;
6

          
7
    @RunWith(JUnitQuickcheck.class)
8
    public class StringProperties {
9
        @Property public void concatenationLength(String s1, String s2) {
10
            assertEquals(s1.length() + s2.length(), (s1 + s2).length());
11
        }
12
    }



Several examples are located here to get an idea of how to use the framework and which benefits you may earn.

Framework Playwright

Playwright is another E2E JS testing framework publishing by Microsoft in 2020.

Among the interesting features provided by the framework:

  • Test for mobile: Use device emulation to test your responsive web apps in mobile web browsers.
  • Auto-wait APIs: Playwright interactions auto-wait for elements to be ready. This improves reliability and simplifies test authoring.
  • Timeout-free automation: Playwright receives browser signals, like network requests, page navigations, and page load events to eliminate the need for sleep timeouts that cause flakiness

My personal opinion is to have a look at it since the integration with Robot Framework confirmed.

JQF

JQF is a java Fuzzy test library to perform fuzzy testing on your code by varying the values of the parameters and potentially discover bugs you have never thought about before.

JSON
 




xxxxxxxxxx
1
15


 
1
@RunWith(JQF.class)
2
public class PatriciaTrieTest {
3

          
4
    @Fuzz  /* The args to this method will be generated automatically by JQF */
5
    public void testMap2Trie(Map<String, Integer> map, String key) {
6
        // Key should exist in map
7
        assumeTrue(map.containsKey(key));   // the test is invalid if this predicate is not true
8

          
9
        // Create new trie with input `map`
10
        Trie trie = new PatriciaTrie(map);
11

          
12
        // The key should exist in the trie as well
13
        assertTrue(trie.containsKey(key));  // fails when map = {"x": 1, "x\0": 2} and key = "x"
14
    }
15
}



The JQF Maven Plugin documentation shows how to run mvn jqf:fuzz.

PODAM

PODAM is a lightweight tool to auto-fill Java POJOs with data. This comes in handy when developing unit tests.

JavaScript
 




xxxxxxxxxx
1
15


 
1
// Simplest scenario. Will delegate to Podam all decisions
2
PodamFactory factory = new PodamFactoryImpl();
3

          
4
// This will use constructor with minimum arguments and
5
// then setters to populate POJO
6
Pojo myPojo = factory.manufacturePojo(Pojo.class);
7

          
8
// This will use constructor with maximum arguments and
9
// then setters to populate POJO
10
Pojo myPojo2 = factory.manufacturePojoWithFullData(Pojo.class);
11

          
12
// If object instance is already available,
13
// Podam can fill it with random data
14
Pojo myPojo3 = MyFactory.getPojoInstance();
15
factory.populatePojo(myPojo3);



It is another version of a Random library like RandomBeans for which I am a frequent user.  PODAM is extensible and you can create your own generators. If you do not like Randombeans, have a look at PODAM.

Conclusion

In this article, we discussed 6 test frameworks I didn’t know and if one should stand out above all others, it would definitely by RobotFramework. Which framework do you want to use in 2021?

Framework Testing

Published at DZone with permission of Sylvain Leroy. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Toying With Kotlin’s Context Receivers
  • Implementing RBAC Configuration for Kubernetes Applications
  • Best Practices for Resource Management in PrestoDB
  • A Guide to Events in Vue

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo