0
0
Apache Airflowdevops~20 mins

Unit testing DAGs in Apache Airflow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Airflow DAG Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of a simple DAG test run
You have a DAG with one task that prints 'Hello Airflow'. You run a unit test that triggers this task. What will be the output of the test command?
Apache Airflow
def test_hello_task():
    ti = TaskInstance(task=hello_task, execution_date=datetime.now())
    ti.run()
    print(ti.xcom_pull())
ANone
BTaskInstanceError
CSyntaxError
DHello Airflow
Attempts:
2 left
💡 Hint
Think about what xcom_pull returns if no value is pushed.
🧠 Conceptual
intermediate
1:30remaining
Purpose of mocking in DAG unit tests
Why do we use mocking when unit testing Airflow DAGs?
ATo deploy DAGs automatically
BTo simulate external systems and isolate the DAG logic
CTo speed up the Airflow scheduler
DTo generate DAG documentation
Attempts:
2 left
💡 Hint
Think about how to test code without relying on real external services.
Troubleshoot
advanced
2:00remaining
Diagnosing a failing DAG unit test
A unit test for a DAG task fails with the error: 'TaskInstanceStateError: Task instance is in state None'. What is the most likely cause?
AThe task was not properly initialized with an execution date
BThe DAG file has syntax errors
CThe Airflow webserver is down
DThe task has no downstream dependencies
Attempts:
2 left
💡 Hint
Check how TaskInstance is created in tests.
Best Practice
advanced
1:30remaining
Best practice for testing task dependencies in DAGs
Which approach best verifies task dependencies in an Airflow DAG unit test?
AManually inspect the DAG Python file
BRun all tasks and check their logs
CUse Airflow CLI to list all DAGs
DCheck the DAG's task dictionary for upstream and downstream task IDs
Attempts:
2 left
💡 Hint
Think about programmatic ways to verify dependencies.
🔀 Workflow
expert
2:30remaining
Correct order of steps in unit testing an Airflow DAG
Arrange the following steps in the correct order for unit testing an Airflow DAG:
A3,1,2,4
B1,3,2,4
C1,2,3,4
D2,1,3,4
Attempts:
2 left
💡 Hint
Think about preparing the environment before running tests.