Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
I want to write tests for functions in fabric notebooks of the type: given this dataframe (read from file or code) do the transformation and check if resulting dataframe is like so and so.
How do I do this in fabric?
I want the test runs to be called from CI/CD.
However, I can find very little written about this. Maybe I am just not looking in the right places.
Hi @ex_kjetilh,
Below is a practical way to unit-test PySpark transformations from Fabric notebooks and run them in CI/CD. It boils down to: put your transform logic in plain Python modules, test them with pytest + a local Spark session (or Spark’s own testing helpers), and optionally add Fabric-side integration tests for end-to-end coverage.
# tests/conftest.py
import pytest
from pyspark.sql import SparkSession
@pytest.fixture(scope="session")
def spark():
return (SparkSession.builder
.master("local[*]")
.appName("unit-tests")
.getOrCreate())
# tests/test_transforms.py
from pyspark.sql import Row
from your_pkg.transforms import clean_and_join
from pyspark.testing import assertDataFrameEqual # Spark ≥ 4.x
def test_clean_and_join(spark):
left = spark.createDataFrame([Row(id=1, v="a "), Row(id=2, v="b")])
right = spark.createDataFrame([Row(id=1, w=10), Row(id=2, w=20)])
actual = clean_and_join(left, right) # your transform
expected = spark.createDataFrame([Row(id=1, v="a", w=10), Row(id=2, v="b", w=20)])
assertDataFrameEqual(actual, expected, checkRowOrder=False)
name: unit-tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with: { python-version: '3.10' }
- name: Install Java for Spark
uses: actions/setup-java@v4
with: { distribution: 'temurin', java-version: '11' }
- name: Install deps
run: |
pip install "pyspark==<match_Fabric_runtime>" pytest chispa
- name: Run pytest
run: pytest -q --maxfail=1 --disable-warnings
Fabric CI/CD background: Deployment pipelines overview, Git integration overview. Good write-ups with examples: Unit tests on Microsoft Fabric items (pytest), Optimizing for CI/CD in Microsoft Fabric.
If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, mark this post as the solution.
Hi @ex_kjetilh,
We would like to confirm if our community members answer resolves your query or if you need further help. If you still have any questions or need more support, please feel free to let us know. We are happy to help you.
@tayloramy ,Thanks for your prompt response
Thank you for your patience and look forward to hearing from you.
Best Regards,
Prashanth Are
MS Fabric community support
I wrote a post some time ago relating to this, I hope it helps:
https://www.kevinrchant.com/2024/08/30/unit-tests-on-microsoft-fabric-items/
Check out the November 2025 Fabric update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!