Predictive Testing in JavaScript with Machine Learning

Rate this content
Bookmark

This talk will cover how we can apply machine learning to software testing including in Javascript, to help reduce the number of tests that need to be run.

We can use predictive machine learning model to make an informed decision to rule out tests that are extremely unlikely to uncover an issue. This opens up a new, more efficient way of selecting tests.

FAQ

Predictive testing in JavaScript with machine learning involves using AI to generate test cases automatically, select the most relevant tests for specific code changes, and achieve higher code coverage. This approach leverages historical data and machine learning algorithms to optimize the testing process, making it more efficient and effective.

Machine learning can improve software testing by automating test case generation, prioritizing the most relevant tests to run, and enhancing code coverage analysis. It can analyze historical testing data to predict and suggest the most effective tests for new code changes, thereby reducing the time and effort required in manual testing processes.

Real-world applications of AI in software testing include automated test case generation, integration with testing frameworks like Selenium for improved automation, and the use of AI tools like GitHub Copilot for code suggestions. AI helps in identifying critical tests, reducing redundant tests, and ensuring comprehensive code coverage.

While AI can significantly enhance testing efficiency by automating many aspects, it cannot fully replace manual testing. Human oversight is crucial for handling complex test scenarios, understanding user experiences, and making strategic decisions based on the context that AI might not fully grasp.

TensorFlow.JS plays a critical role in AI-based testing by allowing the integration of machine learning models directly into JavaScript applications. It enables the execution of models in the browser or on Node.js, facilitating on-the-fly test case generation and other AI-driven testing processes directly in JavaScript environments.

AI contributes to regression testing by analyzing past test cases and code changes to predict the likelihood of new changes causing failures. This allows testers to focus on high-risk areas more effectively, improving the quality of the software and efficiency of the testing process.

Integrating AI with JavaScript testing frameworks like Jest or Jasmine can help automate the generation of test cases, suggest relevant tests based on code changes, and improve regression testing. This integration enhances test efficiency, coverage, and accuracy, leading to higher quality applications.

Shivay Lamba
Shivay Lamba
18 min
19 Nov, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

This Talk explores the benefits of introducing machine learning to software testing, including automating test case generation and achieving close to 100% code coverage. AI is being used to automate test generation, improve regression testing, and make predictions in automation testing. Machine learning enables predictive testing by selecting tests that are more likely to uncover issues in code changes. AI-based tools are being used to generate automated tests, improve code coverage, and intelligently select tests. Companies are relying on dedicated testers and using historical code changes and test cases to generate specific test cases for relevant code changes.

1. Introduction to Predictive Testing in JavaScript

Short description:

Hello, everyone! Welcome to TestJS Summit 2021. I'm Shivaay, and I'll be presenting on predictive testing in JavaScript with machine learning. Let's get started!

Hello, everyone, welcome to TestJS Summit 2021, and I'm Shivaay, who is going to be presenting a topic on predictive testing in JavaScript with machine learning. So a very quick introduction about myself, I'm Shivaay and I'm currently a TensorFlow.JS Working Group member. I'm a Google Server Code mentor at TensorFlow and this is my third GitNation conference talk this year. Previously, I've also given a talk at Node.js conference and also React Advanced this year. So really excited to be presenting yet another talk at GitNation, specifically at TestJS Summit. So without wasting any further time, let's get started.

2. Introducing Machine Learning to Software Testing

Short description:

Machine learning is being used in various industries, including software development. However, software testing has not fully utilized AI and machine learning. This talk discusses the benefits of introducing machine learning to software testing. AI can automate test case generation, determine which tests are most important, and achieve close to 100% code coverage. AI can also improve automation testing frameworks like Selenium by identifying and resolving issues.

Now, first one, machine learning is really everywhere today. There is no doubt in that particular fact. You can see machine learning being used in healthcare, education, but also when it comes to things within software development itself. Machine learning today is being used to do a lot of different things. For example, we have seen how GitHub Copilot is being used today to auto-generate or auto-suggest new code. It's also being used in MLOps, in different forms of operations in DevOps to improve the DevOps cycles. And that sort of makes it really important to also use it in other areas where we traditionally might not think that it might be able to be used. So that's what makes machine learning really powerful today. And that's why, why not just think about introducing machine learning to software testing?

Software testing has traditionally been all about being able to write test cases, being able to sort of understand fundamentally within the entire software engineering lifecycle that how can we actually make our softwares more and more productive and make them error free. So what that means is that ideally what happens if you have a software tester or a QA analyst, they'll be going through the entire code and writing unit test cases. And of course, we have the entire pipeline of how the testing actually starts off, where first we write some code, then we prepare the unit tests, we have integration tests. And based on this, once the test cases are passed and our code passes through all these different test cases from both the unit and the integration test, then we finally put our code into production. We also use things such as regression testing to be able to see how is new code actually impacting the code that has been written prior to or let's say, some of the older code bases and how this code is actually getting affected. So all of these different processes involve basically either you can use manual testing or you also have a lot of different automation testing tools as well for example like Selenium. And these traditionally haven't really used machine learning. It has more to do with actually writing these test cases if you're doing manual testing or even if you're using automation testing tools such as Selenium to be able to configure them so that they are able to go through your application. And generally, the software testing has not really seen a lot of use of AI but this talk specifically will talk about how we can introduce and what are the benefits of actually adding machine learning or AI to software testing.

So, write about some of the great scenarios where AI could be actually used in testing. So the first one is the automated test case generation. So a lot of time what happens is that we spend a lot of time in actually creating test cases. Now that could be behavior driven programming or behavior driven development where we're creating the test cases before writing the code itself or let's say we have written a particular function and we write a unit test case for it. How can we actually use AI to generate test cases on fly by just evaluating the code by going through the code? Where an AI model just understands whatever code has been written, whatever code changes have been made to the code and then automatically generate test cases without any manual intervention? Then, essentially, being able to find out which particular tests to actually run that are more important that will essentially save time and sort of the entire process of the software testing time where we are only running the most important test cases. I'll also be coming into more deeper discussions specifically on the second point and then how we can actually use machine learning to not only test frontend based UI testing specifically on, say, JavaScript, but also how we can use machine learning to actually test out backend APIs. That's also one of the fields where today a lot of AI-based software testing tools are being worked on. And then how can we achieve 100% code coverage with the help of AI? Because code coverage is a really important topic to be used whenever we are evaluating any type of code base, whenever, let's say, we are creating a new build or we are testing out new deployments, new changes that have been made. If you're able to achieve even 90% or 95% code coverage, that itself is considered to be a really great point. But how can we achieve close to 100% code coverage with the help of AI? And that is something that AI can actually help with, because of the fact that we are able to evaluate the code with the help of AI and we are able to generate automated tests, we are able to run the most important tests that are really important for that particular code change, and that will actually help to just understand all the different nuances of the code that are there, including the code changes and how the new changes have actually impacted your older code. All of that can be considered while trying to do code coverage with the help of AI. And then even within the automation testing framework, how can we actually use AI, or you know, let's say, with respect to Selenium, so that whenever you're doing any kind of an automated testing, AI can actually help improve it by looking specifically at the issues that might arise, and we are like using a manual, we are using basically automation testing to look specifically for those particular issues and try to be able to resolve them. So, those are some of the scenarios today where AI is actually being used in software testing.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Network Requests with Cypress
TestJS Summit 2021TestJS Summit 2021
33 min
Network Requests with Cypress
Top Content
Whether you're testing your UI or API, Cypress gives you all the tools needed to work with and manage network requests. This intermediate-level task demonstrates how to use the cy.request and cy.intercept commands to execute, spy on, and stub network requests while testing your application in the browser. Learn how the commands work as well as use cases for each, including best practices for testing and mocking your network requests.
Testing Pyramid Makes Little Sense, What We Can Use Instead
TestJS Summit 2021TestJS Summit 2021
38 min
Testing Pyramid Makes Little Sense, What We Can Use Instead
Top Content
Featured Video
Gleb Bahmutov
Roman Sandler
2 authors
The testing pyramid - the canonical shape of tests that defined what types of tests we need to write to make sure the app works - is ... obsolete. In this presentation, Roman Sandler and Gleb Bahmutov argue what the testing shape works better for today's web applications.
Full-Circle Testing With Cypress
TestJS Summit 2022TestJS Summit 2022
27 min
Full-Circle Testing With Cypress
Top Content
Cypress has taken the world by storm by brining an easy to use tool for end to end testing. It’s capabilities have proven to be be useful for creating stable tests for frontend applications. But end to end testing is just a small part of testing efforts. What about your API? What about your components? Well, in my talk I would like to show you how we can start with end-to-end tests, go deeper with component testing and then move up to testing our API, circ
Test Effective Development
TestJS Summit 2021TestJS Summit 2021
31 min
Test Effective Development
Top Content
Developers want to sleep tight knowing they didn't break production. Companies want to be efficient in order to meet their customer needs faster and to gain competitive advantage sooner. We ALL want to be cost effective... or shall I say... TEST EFFECTIVE!But how do we do that?Are the "unit" and "integration" terminology serves us right?Or is it time for a change? When should we use either strategy to maximize our "test effectiveness"?In this talk I'll show you a brand new way to think about cost effective testing with new strategies and new testing terms!It’s time to go DEEPER!
Playwright Test Runner
TestJS Summit 2021TestJS Summit 2021
25 min
Playwright Test Runner
Top Content
Charlie Gerard's Career Advice: Be intentional about how you spend your time and effort
6 min
Charlie Gerard's Career Advice: Be intentional about how you spend your time and effort
Featured Article
Charlie Gerard
Jan Tomes
2 authors
When it comes to career, Charlie has one trick: to focus. But that doesn’t mean that you shouldn’t try different things — currently a senior front-end developer at Netlify, she is also a sought-after speaker, mentor, and a machine learning trailblazer of the JavaScript universe. "Experiment with things, but build expertise in a specific area," she advises.

What led you to software engineering?My background is in digital marketing, so I started my career as a project manager in advertising agencies. After a couple of years of doing that, I realized that I wasn't learning and growing as much as I wanted to. I was interested in learning more about building websites, so I quit my job and signed up for an intensive coding boot camp called General Assembly. I absolutely loved it and started my career in tech from there.
 What is the most impactful thing you ever did to boost your career?I think it might be public speaking. Going on stage to share knowledge about things I learned while building my side projects gave me the opportunity to meet a lot of people in the industry, learn a ton from watching other people's talks and, for lack of better words, build a personal brand.
 What would be your three tips for engineers to level up their career?Practice your communication skills. I can't stress enough how important it is to be able to explain things in a way anyone can understand, but also communicate in a way that's inclusive and creates an environment where team members feel safe and welcome to contribute ideas, ask questions, and give feedback. In addition, build some expertise in a specific area. I'm a huge fan of learning and experimenting with lots of technologies but as you grow in your career, there comes a time where you need to pick an area to focus on to build more profound knowledge. This could be in a specific language like JavaScript or Python or in a practice like accessibility or web performance. It doesn't mean you shouldn't keep in touch with anything else that's going on in the industry, but it means that you focus on an area you want to have more expertise in. If you could be the "go-to" person for something, what would you want it to be? 
 And lastly, be intentional about how you spend your time and effort. Saying yes to everything isn't always helpful if it doesn't serve your goals. No matter the job, there are always projects and tasks that will help you reach your goals and some that won't. If you can, try to focus on the tasks that will grow the skills you want to grow or help you get the next job you'd like to have.
 What are you working on right now?Recently I've taken a pretty big break from side projects, but the next one I'd like to work on is a prototype of a tool that would allow hands-free coding using gaze detection. 
 Do you have some rituals that keep you focused and goal-oriented?Usually, when I come up with a side project idea I'm really excited about, that excitement is enough to keep me motivated. That's why I tend to avoid spending time on things I'm not genuinely interested in. Otherwise, breaking down projects into smaller chunks allows me to fit them better in my schedule. I make sure to take enough breaks, so I maintain a certain level of energy and motivation to finish what I have in mind.
 You wrote a book called Practical Machine Learning in JavaScript. What got you so excited about the connection between JavaScript and ML?The release of TensorFlow.js opened up the world of ML to frontend devs, and this is what really got me excited. I had machine learning on my list of things I wanted to learn for a few years, but I didn't start looking into it before because I knew I'd have to learn another language as well, like Python, for example. As soon as I realized it was now available in JS, that removed a big barrier and made it a lot more approachable. Considering that you can use JavaScript to build lots of different applications, including augmented reality, virtual reality, and IoT, and combine them with machine learning as well as some fun web APIs felt super exciting to me.


Where do you see the fields going together in the future, near or far? I'd love to see more AI-powered web applications in the future, especially as machine learning models get smaller and more performant. However, it seems like the adoption of ML in JS is still rather low. Considering the amount of content we post online, there could be great opportunities to build tools that assist you in writing blog posts or that can automatically edit podcasts and videos. There are lots of tasks we do that feel cumbersome that could be made a bit easier with the help of machine learning.
 You are a frequent conference speaker. You have your own blog and even a newsletter. What made you start with content creation?I realized that I love learning new things because I love teaching. I think that if I kept what I know to myself, it would be pretty boring. If I'm excited about something, I want to share the knowledge I gained, and I'd like other people to feel the same excitement I feel. That's definitely what motivated me to start creating content.
 How has content affected your career?I don't track any metrics on my blog or likes and follows on Twitter, so I don't know what created different opportunities. Creating content to share something you built improves the chances of people stumbling upon it and learning more about you and what you like to do, but this is not something that's guaranteed. I think over time, I accumulated enough projects, blog posts, and conference talks that some conferences now invite me, so I don't always apply anymore. I sometimes get invited on podcasts and asked if I want to create video content and things like that. Having a backlog of content helps people better understand who you are and quickly decide if you're the right person for an opportunity.What pieces of your work are you most proud of?It is probably that I've managed to develop a mindset where I set myself hard challenges on my side project, and I'm not scared to fail and push the boundaries of what I think is possible. I don't prefer a particular project, it's more around the creative thinking I've developed over the years that I believe has become a big strength of mine.***Follow Charlie on Twitter

Workshops on related topic

Designing Effective Tests With React Testing Library
React Summit 2023React Summit 2023
151 min
Designing Effective Tests With React Testing Library
Top Content
Featured Workshop
Josh Justice
Josh Justice
React Testing Library is a great framework for React component tests because there are a lot of questions it answers for you, so you don’t need to worry about those questions. But that doesn’t mean testing is easy. There are still a lot of questions you have to figure out for yourself: How many component tests should you write vs end-to-end tests or lower-level unit tests? How can you test a certain line of code that is tricky to test? And what in the world are you supposed to do about that persistent act() warning?
In this three-hour workshop we’ll introduce React Testing Library along with a mental model for how to think about designing your component tests. This mental model will help you see how to test each bit of logic, whether or not to mock dependencies, and will help improve the design of your components. You’ll walk away with the tools, techniques, and principles you need to implement low-cost, high-value component tests.
Table of contents- The different kinds of React application tests, and where component tests fit in- A mental model for thinking about the inputs and outputs of the components you test- Options for selecting DOM elements to verify and interact with them- The value of mocks and why they shouldn’t be avoided- The challenges with asynchrony in RTL tests and how to handle them
Prerequisites- Familiarity with building applications with React- Basic experience writing automated tests with Jest or another unit testing framework- You do not need any experience with React Testing Library- Machine setup: Node LTS, Yarn
How to Start With Cypress
TestJS Summit 2022TestJS Summit 2022
146 min
How to Start With Cypress
Featured WorkshopFree
Filip Hric
Filip Hric
The web has evolved. Finally, testing has also. Cypress is a modern testing tool that answers the testing needs of modern web applications. It has been gaining a lot of traction in the last couple of years, gaining worldwide popularity. If you have been waiting to learn Cypress, wait no more! Filip Hric will guide you through the first steps on how to start using Cypress and set up a project on your own. The good news is, learning Cypress is incredibly easy. You'll write your first test in no time, and then you'll discover how to write a full end-to-end test for a modern web application. You'll learn the core concepts like retry-ability. Discover how to work and interact with your application and learn how to combine API and UI tests. Throughout this whole workshop, we will write code and do practical exercises. You will leave with a hands-on experience that you can translate to your own project.
Detox 101: How to write stable end-to-end tests for your React Native application
React Summit 2022React Summit 2022
117 min
Detox 101: How to write stable end-to-end tests for your React Native application
Top Content
WorkshopFree
Yevheniia Hlovatska
Yevheniia Hlovatska
Compared to unit testing, end-to-end testing aims to interact with your application just like a real user. And as we all know it can be pretty challenging. Especially when we talk about Mobile applications.
Tests rely on many conditions and are considered to be slow and flaky. On the other hand - end-to-end tests can give the greatest confidence that your app is working. And if done right - can become an amazing tool for boosting developer velocity.
Detox is a gray-box end-to-end testing framework for mobile apps. Developed by Wix to solve the problem of slowness and flakiness and used by React Native itself as its E2E testing tool.
Join me on this workshop to learn how to make your mobile end-to-end tests with Detox rock.
Prerequisites- iOS/Android: MacOS Catalina or newer- Android only: Linux- Install before the workshop
API Testing with Postman Workshop
TestJS Summit 2023TestJS Summit 2023
48 min
API Testing with Postman Workshop
Top Content
WorkshopFree
Pooja Mistry
Pooja Mistry
In the ever-evolving landscape of software development, ensuring the reliability and functionality of APIs has become paramount. "API Testing with Postman" is a comprehensive workshop designed to equip participants with the knowledge and skills needed to excel in API testing using Postman, a powerful tool widely adopted by professionals in the field. This workshop delves into the fundamentals of API testing, progresses to advanced testing techniques, and explores automation, performance testing, and multi-protocol support, providing attendees with a holistic understanding of API testing with Postman.
1. Welcome to Postman- Explaining the Postman User Interface (UI)2. Workspace and Collections Collaboration- Understanding Workspaces and their role in collaboration- Exploring the concept of Collections for organizing and executing API requests3. Introduction to API Testing- Covering the basics of API testing and its significance4. Variable Management- Managing environment, global, and collection variables- Utilizing scripting snippets for dynamic data5. Building Testing Workflows- Creating effective testing workflows for comprehensive testing- Utilizing the Collection Runner for test execution- Introduction to Postbot for automated testing6. Advanced Testing- Contract Testing for ensuring API contracts- Using Mock Servers for effective testing- Maximizing productivity with Collection/Workspace templates- Integration Testing and Regression Testing strategies7. Automation with Postman- Leveraging the Postman CLI for automation- Scheduled Runs for regular testing- Integrating Postman into CI/CD pipelines8. Performance Testing- Demonstrating performance testing capabilities (showing the desktop client)- Synchronizing tests with VS Code for streamlined development9. Exploring Advanced Features - Working with Multiple Protocols: GraphQL, gRPC, and more
Join us for this workshop to unlock the full potential of Postman for API testing, streamline your testing processes, and enhance the quality and reliability of your software. Whether you're a beginner or an experienced tester, this workshop will equip you with the skills needed to excel in API testing with Postman.
Testing Web Applications Using Cypress
TestJS Summit - January, 2021TestJS Summit - January, 2021
173 min
Testing Web Applications Using Cypress
WorkshopFree
Gleb Bahmutov
Gleb Bahmutov
This workshop will teach you the basics of writing useful end-to-end tests using Cypress Test Runner.
We will cover writing tests, covering every application feature, structuring tests, intercepting network requests, and setting up the backend data.
Anyone who knows JavaScript programming language and has NPM installed would be able to follow along.
Best Practices for Writing and Debugging Cypress Tests
TestJS Summit 2023TestJS Summit 2023
148 min
Best Practices for Writing and Debugging Cypress Tests
Workshop
Filip Hric
Filip Hric
You probably know the story. You’ve created a couple of tests, and since you are using Cypress, you’ve done this pretty quickly. Seems like nothing is stopping you, but then – failed test. It wasn’t the app, wasn’t an error, the test was… flaky? Well yes. Test design is important no matter what tool you will use, Cypress included. The good news is that Cypress has a couple of tools behind its belt that can help you out. Join me on my workshop, where I’ll guide you away from the valley of anti-patterns into the fields of evergreen, stable tests. We’ll talk about common mistakes when writing your test as well as debug and unveil underlying problems. All with the goal of avoiding flakiness, and designing stable test.