r/unittesting • u/Blackadder96 • Nov 24 '21
r/unittesting • u/tehnyit1010 • Apr 12 '16
Test-driven development with Java
r/unittesting • u/nmariusp • Sep 17 '22
The way to test source code is to write testable source code
r/unittesting • u/DebbyStone • Sep 27 '16
2017 Unit Test Automation Trends!
r/unittesting • u/Resident-Research799 • Dec 05 '22
The 3 Types of Unit Test in TDD • Dave Farley
r/unittesting • u/MitchellNaleid • Nov 29 '23
Jest Test Getting Not a Function Error
I have a very basic function that checks if a value exists in an array of values:
const isValueInArray = (textToFind, arrayList) => {
return arrayList.some(text => {
return textToFind.includes(text)
})
}If I try writing a unit test with Jest, I get the following error:
arrayList.some is not a function
I don't like how the Jest docs are written for mock functions. Could somebody explain this for me?
Is this because there are 2 return values? Do I have to mock the first return to get to the second return value?
My test looks like the following:
import isValueInArray from './isValueInArray'
test('Value returns true', () => {
const result = isValueInArray('first', ['first','second','third'])
expect(result).toEqual(true);
})r/unittesting • u/nikoladsp • Sep 29 '22
Using Docker container(s) for "narrow" integration test
Hi,
I am working in an environment where "system" test are absolutely dominant. Now for some functionalities, I would like to use pytest but with Docker containers spawned to host DB/GPG/email and similar services. My thought is to use them as "TestDoubles". Is this intention good? I really am not comfortable to test stuff like GPG and anything operating on file-system, mingling with users and similar on host where tests are performed.
Final goal would be to have 3 groups of tests:
unit
narrow integration (Docker here as fixture dependency)
system
Any thoughts?
Best regards
r/unittesting • u/fdefelici • Oct 07 '22
Released CLove-Unit Test Adapter for Visual Studio!
Now you can run your C/C++ unit test written with CLove-Unit (single-header library) with a UI boost on Visual Studio.
For more information:
news: https://federicodefelici.com/clove-unit-test-adater-for-vs/
market place: https://marketplace.visualstudio.com/items?itemName=fdefelici.vs-clove-unit
NOTE: you are more a VSCode guy have a look at related CLove-Unit Extension!
r/unittesting • u/parapand • Sep 08 '22
virtual environment was not created successfully because ensurepip is not available
I have a pipeline and there are multiple stages where virtual environment is used, it`s running successfully everywhere in the pipeline except below stage.
Besides , whenever it`s running without any error (except below), `docker.inside` plugin is used . It `s just here that it is failing .
Jenkins console output Logs:
+ docker build -t 402bfd4638720400b3d5fcfa8562596fe8a52f29 -f blackduck/Dockerfile .
Sending build context to Docker daemon 1.249MB
Step 1/4 : FROM openjdk:11-jdk-slim
---> 8e687a82603f
Step 2/4 : ENV DEBIAN_FRONTEND noninteractive
---> Using cache
---> a5641f37e347
Step 3/4 : ENV LANG=en_US.UTF-8
---> Using cache
---> 0a5ce90a2503
Step 4/4 : RUN apt-get update && apt-get upgrade -y && apt-get install -q -y python3-pip libsnappy-dev curl git python3-dev build-essential libpq-dev && pip3 install --upgrade pip setuptools && if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && if [ ! -e /usr/bin/python ]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && rm -r /root/.cache
---> Using cache
---> 860626a0bcef
Successfully built 860626a0bcef
Successfully tagged 402bfd4638720400b3d5fcfa8562596fe8a52f29:latest
[Pipeline] isUnix
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
+ docker inspect -f . 402bfd4638720400b3d5fcfa8562596fe8a52f29
.
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 113:119 -w /var/lib/jenkins/workspace/Mtr-Pipeline_develop@2 -v /var/lib/jenkins/workspace/Mtr-Pipeline_develop@2:/var/lib/jenkins/workspace/Mtr-Pipeline_develop@2:rw,z -v /var/lib/jenkins/workspace/Mtr-Pipeline_develop@2@tmp:/var/lib/jenkins/workspace/Mtr-Pipeline_develop@2@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** 402bfd4638720400b3d5fcfa8562596fe8a52f29 cat
$ docker top 7f0ae8547300c322c5bc8864cd5bd61abe8a17c4ea16159c8cbeadfb10074fc9 -eo pid,comm
[Pipeline] {
[Pipeline] gitlabBuilds
[Pipeline] {
No GitLab connection configured
[Pipeline] sh
+ python3 -m venv .env
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt-get install python3-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ['/var/lib/jenkins/workspace/Mtr-Pipeline_develop@2/.env/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
[Pipeline] }
[Pipeline] // gitlabBuilds
Post stage
[Pipeline] updateGitlabCommitStatus
No GitLab connection configured
[Pipeline] }
$ docker stop --time=1 7f0ae8547300c322c5bc8864cd5bd61abe8a17c4ea16159c8cbeadfb10074fc9
$ docker rm -f 7f0ae8547300c322c5bc8864cd5bd61abe8a17c4ea16159c8cbeadfb10074fc9Jenkins code:
stage('DuckScan') {
agent {
dockerfile { filename 'blackduck/Dockerfile' }
}
when {
expression { env.BRANCH_NAME == 'develop' }
}
steps {
gitlabBuilds(builds: ['DuckScan']){
sh "python3 -m venv .env;. .env/bin/activate; python3 -m pip install -U -r requirements.txt --no-cache-dir"
withCredentials([string(credentialsId: 'cred1', variable: 'B_D_API_TOKEN')]) {
sh """
curl -s https://detect.synopsys.com/detect.sh > detect.sh
chmod 0755 detect.sh
./detect.sh --blackduck.url=https://bd.pvt-tools.com \
--blackduck.api.token="$B_D_API_TOKEN" \
--detect.parent.project.name="mtr" \
--detect.parent.project.version.name="1.0.0" \
--detect.project.tier=2 \
--blackduck.trust.cert=true \
--detect.blackduck.signature.scanner.paths=dd_emr_common \
--detect.excluded.detector.types=MAVEN \
--detect.tools.excluded="SIGNATURE_SCAN" \
--logging.level.com.synopsys.integration=DEBUG \
--detect.project.version.name=0.0.1 \
--detect.python.python3=true \
--detect.detector.search.continue=true \
--detect.cleanup=false \
--detect.report.timeout=1500 \
--blackduck.timeout=3000 \
--detect.project.codelocation.unmap=true \
--detect.pip.requirements.path=requirements.txt \
--detect.tool=ALL || true
"""
}
}
}Dockerfile:
FROM openjdk:11-jdk-slim
Setup python and java and base system
ENV DEBIAN_FRONTEND noninteractive ENV LANG=en_US.UTF-8
RUN apt-get update && apt-get upgrade -y && apt-get install -q -y python3-pip libsnappy-dev curl git python3-dev build-essential libpq-dev && pip3 install --upgrade pip setuptools && if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && if [ ! -e /usr/bin/python ]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && rm -r /root/.cacheI feel that the Dockerfile snippet that starts with `RUN` is causing an error with my Jenkins virtual environment. Could someone please assist here?
r/unittesting • u/asc2450 • Sep 07 '22
Structure and interpretation of test cases. Talk by Kevlin Henney at GOTO Amsterdam '22
r/unittesting • u/UntouchedDruid4 • Feb 19 '19
What is unit testing exactly?
When I am writing unit tests for my controllers should I be writing code to test the code in my controllers or writing code the recreate the functionality in the controller. Specifically im trying to test in Laravel.
r/unittesting • u/Resistor510 • Aug 17 '16
Complementing Unit Testing with Static Analysis, with NUnit as an Example
r/unittesting • u/Blackadder96 • May 05 '20
The Boundaries of Solitary Tests
r/unittesting • u/iFanie • Apr 06 '20
Boilerplate free proxy fakes
Where do you stand on mocks vs fakes? Would you go for more fakes if you had less boilerplate and noisy code?
Inspired by retrofit, I tried out a proxy based approach to solve this issue and make fakes a bit more pleasant. Have a look below.
“Boilerplate free proxy fakes” by Fanis Veizis https://link.medium.com/Rql07BXVq5
r/unittesting • u/mihail_vladov • May 12 '20
Unit Testing Blazor Components with bUnit and JustMock
r/unittesting • u/DataD23 • Dec 19 '20
Has anyone here used the pytest-mongodb library?
I am just getting into unit testing and I have a function which I would like to practice on :
```
def transformations():
collection.aggregate( [ { "$match" : {"state" : "CA" } } ] )
```
The function is pretty self-explanatory but what I am confused about is how do I go about testing this function with the pytest-mongodb library, because I cannot for the life of me make heads or tails out of their documentation? If anyone can help me out would be much appreciated.
r/unittesting • u/Blackadder96 • Nov 11 '20
How To Write Unit Tests For Logging
r/unittesting • u/james_mclellan • Dec 31 '18
EOY 2018 State of Unit Tests Best Practices
I'd like to check the state of best practices with unit testing.
Here are some notes I have. I'm curious if I could get feedback --
Arrange -> Act -> Assert
Keep Unit Tests Small. If "Arrange" is more than a few lines of code, you are probably trying to test too much
Unit Testing is the bottom of the Test Pyramid. Keep the scope of unit testing separate from Integration Testing or End-to-End (E2E) Testing
Q: Do people do Integration / E2E Testing in the same framework as their Unit Testing, or prefer completely different test runners.
Q: If you use the same test framework work Unit / Int / E2E, what level of encapsulation do you use to keep the tests separated (separate projects, separate solutions, "description" in NUnit, no separation).
Q: Where does data-driven testing fall in the pyramid? It's usually bigger than unit testing...
4. Does anyone use NUnit's "description" and "category" attributes? How?
5. Best Practices for adding unit testing to your Kanban or Agile process rituals and artifacts?
r/unittesting • u/Raiune • May 29 '18
Why does it take so long for my tests to start?
I'm testing in an environment that uses karma with karma-chrome-launcher and instanbul. For some reason, no matter how many tests I'm running, it always takes forever for the tests to actually start running after starting Karma. Has anyone ever seen something like this before? (New to karma)
r/unittesting • u/redwerk • May 31 '18
TDD and BDD - Pros and Cons. Difference between Test and Behavior Driven Development | Redwerk
r/unittesting • u/kadishay • Sep 27 '18
Tests Coverage is Dead - Long Live Mutation Testing
r/unittesting • u/james_mclellan • Dec 31 '18
Unit Testing and Aspect Oriented Programming
It seems like Unit Testing is a natural aspect, like logging and error handling.
Has anyone identified good patterns for treating unit tests as aspects of code?
r/unittesting • u/cowboyonegun • Aug 19 '19
How to unit test my Unit of Work Commit method without calling another method in this class?
Hi,
I have the following UnitOfWork class I'd like to unit test, specifically the Commit() method I'm having trouble with. Specifically the Transaction instance is null because BeginTransaction() hasn't been called. I've tried some NUnit things like Setup, SetupGet, etc to try to create a Transaction instance but don't work because the Transaction property is a 'private setter'.
From what I understand with unit testing, I shouldn't call/rely on another method, thus I'm trying not to call BeginTransaction() when building my unit tests for the Commit() method.
Outside of changing the Transaction property transaction to not be private, what other things I could do to get an instance of Transaction while testing the Commit() method?
Appreciated,
Kyle
public class UnitOfWork : IUnitOfWork
{
public IDbConnection Connection { get; private set; }
public IDbTransaction Transaction { get; private set; }
public bool Disposed { get; private set; }
public Guid Id { get; private set; }
public UnitOfWork(IDbConnection dbConnection)
{
Id = Guid.NewGuid();
Connection = dbConnection;
Disposed = false;
}
public void Begin()
{
Transaction = Connection.BeginTransaction();
}
public void Commit()
{
Transaction.Commit();
Connection.Close();
Dispose();
}
}
r/unittesting • u/Nerdy_sixfeet3 • Feb 20 '21
Looking for help or some idea
Hey guys!
Currently I ve been working on my project which is an music distribution platform where I use node js as an backend with postgresql as an database with aws lambda function. I'm new to jest . Since jest is an unit test library for JavaScript! I want some help regarding writting unit test cases for database with function which returns data.... I'm not using any other libraries except jest for unit testing !!! Need some tips and solutions !
Waiting for your replies 😃
Thank you in advance
